Retab and cleanup

This commit is contained in:
sqozz 2018-02-20 18:37:13 +01:00
parent aff5a6d5b2
commit 0cc2aaf4fe

View file

@ -2,54 +2,54 @@
#include "secrets.h"
void setup() {
pinMode(12, OUTPUT); // relay
pinMode(13, OUTPUT); // button
pinMode(0, INPUT); // led
Serial.begin(9600);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
pinMode(12, OUTPUT); // relay
pinMode(13, OUTPUT); // button
pinMode(0, INPUT); // led
Serial.begin(9600);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(13, !digitalRead(13));
delay(500);
Serial.print(".");
}
while (WiFi.status() != WL_CONNECTED) {
digitalWrite(13, !digitalRead(13));
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
bool still_pressed = false;
void loop() {
if(!digitalRead(0)) {
uint8_t relay_status = digitalRead(12);
Serial.print("Old status: ");
Serial.println(relay_status);
digitalWrite(13, !relay_status); // set LED
digitalWrite(12, !relay_status); // set relay
delay(200);
if(!digitalRead(0)) {
still_pressed = true;
} else {
still_pressed = false;
}
}
if(!digitalRead(0)) {
uint8_t relay_status = digitalRead(12);
Serial.print("Old status: ");
Serial.println(relay_status);
digitalWrite(13, !relay_status); // set LED
digitalWrite(12, !relay_status); // set relay
delay(200);
if(!digitalRead(0)) {
still_pressed = true;
} else {
still_pressed = false;
}
}
if (still_pressed) {
software_reset();
}
if (still_pressed) {
software_reset();
}
delay(10);
delay(10);
}
void software_reset() {
wdt_enable(WDTO_15MS);
while(1) {};
wdt_enable(WDTO_15MS);
while(1) {};
}