-
Notifications
You must be signed in to change notification settings - Fork 1
/
LightControlArduino.ino
68 lines (55 loc) · 1.28 KB
/
LightControlArduino.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include "Config.h"
#include "Control.h"
Control ctrl;
//boolean debug = false;
boolean debug = true;
int times = 7;
void checkButtonTime(){
int reading = digitalRead(ctrl.pin_button);
if (reading != ctrl.lastbutton_state) {
ctrl.lastDebounceTime = millis();
}
if ((millis() - ctrl.lastDebounceTime) > ctrl.debounceDelay) {
if (reading != ctrl.button_state) {
ctrl.button_state = reading;
if (ctrl.button_state == LOW) {
ctrl.light_state = !ctrl.light_state;
}
}
}
digitalWrite(ctrl.pin_light,ctrl.light_state);
ctrl.lastbutton_state = reading;
}
void setup() {
pinMode(ctrl.pin_light, OUTPUT);
pinMode(ctrl.pin_button, INPUT);
digitalWrite(ctrl.pin_light, ctrl.light_state);
if(debug){
Serial.begin(115200);
Serial.print("wait is ");
Serial.println(times);
}
WiFiManager wifi(debug);
int r = wifi.autoConnect();
if(r == 2){
while(1){
delay(1000);
yield();
times++;
if(times >= 7)
break;
}
if(debug)
Serial.println("Rebooting....");
ESP.restart();
}
ctrl.begin(debug);
if(debug)
Serial.println("Wifi OK, pode usar agora....");
}
void loop() {
checkButtonTime();
ctrl.handleClient();
}