#include #include // Pins #define SWITCH 0 #define SENDER 2 #define CONTROLLER 4 ContactSensor sensor = ContactSensor(WINDOW1, SENDER); volatile int counter = 0; volatile bool shouldSend = true; void setup() { pinMode(SWITCH, INPUT_PULLUP); pinMode(CONTROLLER, OUTPUT); digitalWrite(CONTROLLER, LOW); sensor.setup(); TinyPower::setup(); TinyPower::enableWdt(WDTO_8S); } void loop() { if (shouldSend) { shouldSend = false; sensor.sendStateAndVoltage(digitalRead(SWITCH)); } TinyPower::sleep(); } ISR(PCINT0_vect) { shouldSend = true; wdt_reset(); TinyPower::enableWdt(WDTO_8S); counter = 0; } ISR(WDT_vect) { counter++; if (counter == 1) { shouldSend = true; return; } if (counter % 75 == 0) { shouldSend = true; } if (counter >= 225) { TinyPower::disableWdt(); counter = 0; } }