Initial POC

This commit is contained in:
sqozz 2018-02-19 20:22:45 +01:00
commit 84504b052f

57
switcheroo.ino Normal file
View file

@ -0,0 +1,57 @@
#include <ESP8266WiFi.h>
const char* ssid = "sendepunkt";
const char* password = "";
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) {};
}