From 8c52520ab0a41f5c174fe0300008e882c44064ac Mon Sep 17 00:00:00 2001 From: Nicu Hodos Date: Fri, 11 Sep 2020 21:36:19 +0200 Subject: [PATCH] add movemnt sensor for basement --- movement_sensor/movement_sensor.ino | 32 +++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 movement_sensor/movement_sensor.ino diff --git a/movement_sensor/movement_sensor.ino b/movement_sensor/movement_sensor.ino new file mode 100644 index 0000000..6870840 --- /dev/null +++ b/movement_sensor/movement_sensor.ino @@ -0,0 +1,32 @@ +#include +#include +#include + +// Pins +#define MOVEMENT_PIN PCINT2 +#define SENDER 4 + +ContactSensor sensor = ContactSensor(MOVEMENT_SENSOR, SENDER); + +volatile bool shouldSend = false; + +void setup() { + + pinMode(MOVEMENT_PIN, INPUT_PULLUP); + sensor.setup(); + TinyPower::setup(); + PCMSK |= (1 << MOVEMENT_PIN); +} + +void loop() { + if (shouldSend) { + shouldSend = false; + int currentState = digitalRead(MOVEMENT_PIN); + sensor.sendState(!currentState); + } + TinyPower::sleep(); +} + +ISR(PCINT0_vect) { + shouldSend = true; +}