[问题] Arduino 注解程式码后动作不正常

楼主: yimean (温柔杀手)   2020-07-26 13:22:41
各位版上的大大下午好
我是Arduino初心者,买了一个教学盒按表操课。
如果什么都不改的话确实可以动作,但是,我觉得他的wifi连线动作太慢,
所以做了一些修改,结果最后把Serial.println这行注解掉后动作就不正常了。
原始程式码如下
// Flag's Block 产生的草稿码
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include "data/webpages.h"
int resistor_of_skin;
unsigned long Time_counter;
int lie_value;
ESP8266WebServer _esp8266WebServer(80);
void handleRoot() {
#ifndef WEBPAGE_IN_PROGMEM
_esp8266WebServer.send(200, "text/html", mainPage);
#else
_esp8266WebServer.send_P(200, PSTR("text/html"), mainPage);
#endif
}
void handleNotFound() {
#ifndef WEBPAGE_IN_PROGMEM
_esp8266WebServer.send(404, "text/html", errorPage);
#else
_esp8266WebServer.send_P(404, PSTR("text/html"), errorPage);
#endif
}
void handleSetting() {
#ifndef WEBPAGE_IN_PROGMEM
_esp8266WebServer.send(200, "text/html", settingPage);
#else
_esp8266WebServer.send_P(200, PSTR("text/html"), settingPage);
#endif
}
void lie_return() {
_esp8266WebServer.send(200, u8"text/plain", String(lie_value));
}
void lie_transfer(int resistor_of_skin) {
resistor_of_skin = (resistor_of_skin < 10 ? 10 : ( resistor_of_skin > 40 ?
40 : resistor_of_skin));
lie_value = (map(resistor_of_skin, 10, 40, 180, 360));
}
// setup() 会先被执行且只会执行一次
void setup() {
Serial.begin(9600);
pinMode(A0, INPUT);
Time_counter = millis();
while (!WiFi.softAP(u8"LocalKing", u8"12345678", 7,false));
_esp8266WebServer.on("/lie", lie_return);
_esp8266WebServer.on("/", handleRoot);
_esp8266WebServer.onNotFound(handleNotFound);
_esp8266WebServer.on("/setting", handleSetting);
_esp8266WebServer.begin();
}
// loop() 里面的程式会不断重复执行
void loop() {
_esp8266WebServer.handleClient();
if (millis() + Time_counter > 1000) {
resistor_of_skin = analogRead(A0);
Serial.println(resistor_of_skin);
lie_transfer(resistor_of_skin);
Time_counter = millis();
}
我作了以下动作
1.把Time_counter全部拿掉,我觉得millis()+Time_counter似乎是多余的。
应该只要留millis()就可以了。
执行正常,但是网页资料传输还是慢。
2.注解//Serial.println(resistor_of_skin);
此时,wifi的ID就完全看不到了。
把注解拿掉,Wifi的ID又可以看到了。
请问高手这是发生什么事,不应该注解掉Serial.println Wifi就看不到阿
烦请解惑感恩
作者: chuegou (chuegou)   2020-07-26 14:10:00
1.的效果是定期执行 你拿掉之后会变成连续执行
楼主: yimean (温柔杀手)   2020-07-26 17:08:00
请问为什么呢?millis()就等于Time_counter不是吗?而一秒钟后,millis()一定会大于1000阿,理论上他本来就会疯狂执行不会休息不是吗?
作者: chuegou (chuegou)   2020-07-26 19:02:00
抱...抱歉 是我看错...
楼主: yimean (温柔杀手)   2020-07-26 19:24:00
@c大,没关系的,看错人人有。感谢你热心回应。
作者: god145145   2020-07-26 22:48:00
if (millis() - Time_counter > 1000) 才对吧
楼主: yimean (温柔杀手)   2020-07-27 09:42:00
@g大,你的推想比较合理,但是这是旗标的Code我没有改
作者: qwe789qwec (我密头芣)   2020-07-27 13:14:00
速度要变快应该可以用7楼的那个方式把1000改掉试试看然后注解掉看不到ID是指在comport那个接口上看不到吗
楼主: yimean (温柔杀手)   2020-07-27 16:13:00
不是,就是电脑要连线就看不到Wifi的ID:LocalKing

Links booklink

Contact Us: admin [ a t ] ucptt.com