#include #include // Pins #define SWITCH 0 #define SENDER 2 #define SENSOR_ID 2 TinySensor sensor = TinySensor(SENSOR_ID, SENDER); int counter = 0; bool currentState; void setup() { pinMode(SWITCH, INPUT_PULLUP); sensor.setup(); updateState(); sensor.sendWindowState(readState()); TinyPower::setup(); TinyPower::enableWdt(); } void loop() { TinyPower::sleep(); } void updateState() { currentState = readState(); } byte readState() { return digitalRead(SWITCH); } ISR(PCINT0_vect) { sensor.sendWindowState(readState()); } ISR(WDT_vect) { bool state = readState(); if (state != currentState) { sensor.sendWindowState(readState()); updateState(); return; } counter++; if (counter % 76 == 0) { sensor.sendWindowState(readState()); counter = 0; } }