#include #include // Pins #define SWITCH 0 #define SENDER 2 ContactSensor sensor = ContactSensor(WINDOW2, SENDER); volatile int counter = 0; volatile bool currentState; volatile bool shouldSend = true; void setup() { pinMode(SWITCH, INPUT_PULLUP); sensor.setup(); TinyPower::setup(); TinyPower::enableWdt(WDTO_8S); } void loop() { if (shouldSend) { shouldSend = false; sensor.sendStateAndVoltage(readState()); } TinyPower::sleep(); } byte readState() { return digitalRead(SWITCH); } ISR(PCINT0_vect) { shouldSend = true; wdt_reset(); counter = 0; } ISR(WDT_vect) { bool state = readState(); if (state != currentState) { shouldSend = true; currentState = state; return; } counter++; if (counter % 225 == 0) { shouldSend = true; counter = 0; } }