Skip to content

Instantly share code, notes, and snippets.

@drbh
Created July 26, 2020 01:03
Show Gist options
  • Save drbh/5f9dd83c5a40263429eba913aed16463 to your computer and use it in GitHub Desktop.
Save drbh/5f9dd83c5a40263429eba913aed16463 to your computer and use it in GitHub Desktop.
Simple door state checker - truncated to ignore networking code
#include <ESP8266WiFi.h>
#include <EEPROM.h>
// networking and request related
int inputVal = 0;
int addr = 0;
int lastValue;
// networking and request related
void sendMessageToLambda(int currentState) {
// networking and request related
}
void setup() {
Serial.begin(9600);
Serial.setTimeout(2000);
Serial.println("");
pinMode(2, OUTPUT);
}
void loop() {
inputVal = digitalRead(2);
if (inputVal > lastValue) {
Serial.println("Turned On");
sendMessageToLambda(inputVal)
}
if (lastValue > inputVal) {
Serial.println("Turned Off");
sendMessageToLambda(inputVal)
}
lastValue = inputVal;
// wait 10 seconds before next check
delay(10000)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment