diff --git a/lamp_switch/lamp_switch.ino b/lamp_switch/lamp_switch.ino index 4012521..9fc3e5b 100644 --- a/lamp_switch/lamp_switch.ino +++ b/lamp_switch/lamp_switch.ino @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/libraries/TinySensor/TinySensor.h b/libraries/Tiny/ContactSensor.h similarity index 92% rename from libraries/TinySensor/TinySensor.h rename to libraries/Tiny/ContactSensor.h index 99c8863..68d1315 100644 --- a/libraries/TinySensor/TinySensor.h +++ b/libraries/Tiny/ContactSensor.h @@ -2,13 +2,13 @@ #include -class TinySensor { +class ContactSensor { short id; short senderPin; RCSwitch mySwitch = RCSwitch(); public: - TinySensor(short id, short senderPin) { + ContactSensor(short id, short senderPin) { this->id = id; this->senderPin = senderPin; } @@ -18,7 +18,7 @@ public: mySwitch.setProtocol(2); } - void sendWindowState(bool state) { + void sendStateAndVoltage(bool state) { unsigned long value = 0x70000000; value |= readVcc() << 6; value |= !state << 5; diff --git a/libraries/Tiny/Tiny.h b/libraries/Tiny/Tiny.h new file mode 100644 index 0000000..76e0528 --- /dev/null +++ b/libraries/Tiny/Tiny.h @@ -0,0 +1,4 @@ +#pragma once + +#include + diff --git a/water_sensor/water_sensor.ino b/water_sensor/water_sensor.ino index c83ff51..1c82c94 100644 --- a/water_sensor/water_sensor.ino +++ b/water_sensor/water_sensor.ino @@ -1,5 +1,5 @@ #include -#include +#include // Pins #define SWITCH 0 @@ -8,7 +8,7 @@ #define SENSOR_ID 3 -TinySensor sensor = TinySensor(SENSOR_ID, SENDER); +ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER); int counter = 0; @@ -19,7 +19,7 @@ void setup() { digitalWrite(CONTROLLER, HIGH); sensor.setup(); - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); TinyPower::setup(); TinyPower::enableWdt(WDTO_8S); @@ -37,17 +37,17 @@ bool readState() { } ISR(PCINT0_vect) { - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); delay(5000); - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); } ISR(WDT_vect) { counter++; if (counter % 220 == 0) { counter = 0; - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); delay(10000); - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); } } diff --git a/window1/window1.ino b/window1/window1.ino index f92e4c4..5f26177 100644 --- a/window1/window1.ino +++ b/window1/window1.ino @@ -1,5 +1,5 @@ #include -#include +#include // Pins #define SWITCH 0 @@ -7,7 +7,7 @@ #define CONTROLLER 4 #define SENSOR_ID 1 -TinySensor sensor = TinySensor(SENSOR_ID, SENDER); +ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER); int counter = 0; bool currentState; @@ -21,7 +21,7 @@ void setup() { sensor.setup(); updateState(); - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); TinyPower::setup(); TinyPower::enableWdt(WDTO_8S); @@ -40,19 +40,19 @@ byte readState() { } ISR(PCINT0_vect) { - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); } ISR(WDT_vect) { bool state = readState(); if (state != currentState) { - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); updateState(); return; } counter++; if (counter % 76 == 0) { - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); counter = 0; } } diff --git a/window2/window2.ino b/window2/window2.ino index fd3def3..56df2a5 100644 --- a/window2/window2.ino +++ b/window2/window2.ino @@ -1,12 +1,12 @@ #include -#include +#include // Pins #define SWITCH 0 #define SENDER 2 #define SENSOR_ID 2 -TinySensor sensor = TinySensor(SENSOR_ID, SENDER); +ContactSensor sensor = ContactSensor(SENSOR_ID, SENDER); int counter = 0; bool currentState; @@ -18,7 +18,7 @@ void setup() { sensor.setup(); updateState(); - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); TinyPower::setup(); TinyPower::enableWdt(WDTO_8S); @@ -37,19 +37,19 @@ byte readState() { } ISR(PCINT0_vect) { - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); } ISR(WDT_vect) { bool state = readState(); if (state != currentState) { - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); updateState(); return; } counter++; if (counter % 76 == 0) { - sensor.sendWindowState(readState()); + sensor.sendStateAndVoltage(readState()); counter = 0; } }