switcheroo/switcheroo.ino

56 lines
1.1 KiB
C++

#include <ESP8266WiFi.h>
#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);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
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());
}
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 (still_pressed) {
software_reset();
}
delay(10);
}
void software_reset() {
wdt_enable(WDTO_15MS);
while(1) {};
}