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