|
点击闪烁后 loop 里面开始执行delay,
点击开关 结束闪烁的时候要等 delay 执行完才能结束,
有没有办法 在 loop delay执行时,
如果点击不闪烁了,可以立即执行不用等delay 结束
[mw_shl_code=arduino,true]//setup接收控制参数
server.on(inlineUrl, []() {
String inlineUrl = "/inline";
String ledargName = "led";
//开灯关灯控制
String ledarg = server.arg(ledargName);
if ( server.arg(ledargName) == "on" ) {
ledIsSS = "no";
ledOn();
}
if ( server.arg(ledargName) == "off" ) {
//if(strcmp( "off" , ledarg ) ){
ledIsSS = "no";
ledOff();
}
if ( server.arg(ledargName) == "scintillating" ) {
//if(strcmp( "scintillating" , ledarg ) ){
ledIsSS = "yes";
ledOff();
}
if (server.hasArg("wifiid") && server.hasArg("wifipwd")) {
ssid = server.arg("wifiid");
password = server.arg("wifipwd");
Serial.print("ssid: ");
Serial.print(ssid);
Serial.print(" , password: ");
Serial.println(password);
WiFi.begin( ssid, password );
//ESP.restart();
restartWifi();
Serial.println(" WebConfilg Ok");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
char buffer[10];
String shiString = dtostrf(dht.getHumidity(), 4, 1, buffer);
String wenString = dtostrf(dht.getTemperature(), 4, 1, buffer);
String str = "<!DOCTYPE html><html><head><meta charset='UTF-8'></head><body>";
str = str + "<h1>湿度: " + shiString + " 温度: " + wenString ;
//内网IP
str = str + "<br/>内网ip: " + localip_to_String() ;
str = str + "<br/>红色LED <a href='" + inlineUrl + "?" + ledargName + "=on'> 开 </a> <span>,</span>";
str = str + " <a href='" + inlineUrl + "?" + ledargName + "=off'> 关 </a> <span>,</span>";
str = str + " <a href='" + inlineUrl + "?" + ledargName + "=scintillating'> 闪烁 </a> ";
str = str + "<br/><form method='POST' action='" + inlineUrl + "'>";
str = str + " wifi <input type='wifiid' name='wifiid' placeholder='名称'>";
str = str + "<input type='text' name='wifipwd' placeholder='密码'>";
str = str + "<input type='submit' value='连接'></form></h1></body></html>";
server.send(200, "text/html", str);
});
//loop判断是否进行闪烁
void loop() {
server.handleClient();
ArduinoOTA.handle();
if ( ledIsSS == "yes" ) {
//if(strcmp(ledIsSS , "yes" ) ){
ledOff();
delay(2000);
ledOn();
delay(2000);
}
}[/mw_shl_code] |
|