when window is opened, continue to send state every 10 mins until it is

closed
This commit is contained in:
Nicu Hodos 2019-02-21 23:15:49 +01:00
parent a84afeea61
commit dd3a05889d
2 changed files with 10 additions and 8 deletions

View File

@ -10,6 +10,7 @@ ContactSensor sensor = ContactSensor(WINDOW1, SENDER);
volatile int counter = 0;
volatile bool shouldSend = true;
bool currentState = false;
void setup() {
@ -26,7 +27,8 @@ void setup() {
void loop() {
if (shouldSend) {
shouldSend = false;
sensor.sendStateAndVoltage(digitalRead(SWITCH));
currentState = digitalRead(SWITCH);
sensor.sendStateAndVoltage(currentState);
}
TinyPower::sleep();
}
@ -34,8 +36,8 @@ void loop() {
ISR(PCINT0_vect) {
shouldSend = true;
wdt_reset();
TinyPower::enableWdt(WDTO_8S);
counter = 0;
TinyPower::enableWdt(WDTO_8S);
}
ISR(WDT_vect) {
@ -47,8 +49,7 @@ ISR(WDT_vect) {
if (counter % 75 == 0) {
shouldSend = true;
}
if (counter >= 225) {
if (!currentState && counter >= 225) {
TinyPower::disableWdt();
counter = 0;
}
}

View File

@ -9,6 +9,7 @@ ContactSensor sensor = ContactSensor(WINDOW2, SENDER);
volatile int counter = 0;
volatile bool shouldSend = true;
bool currentState = false;
void setup() {
@ -23,7 +24,8 @@ void setup() {
void loop() {
if (shouldSend) {
shouldSend = false;
sensor.sendStateAndVoltage(digitalRead(SWITCH));
currentState = digitalRead(SWITCH);
sensor.sendStateAndVoltage(currentState);
}
TinyPower::sleep();
}
@ -31,8 +33,8 @@ void loop() {
ISR(PCINT0_vect) {
shouldSend = true;
wdt_reset();
TinyPower::enableWdt(WDTO_8S);
counter = 0;
TinyPower::enableWdt(WDTO_8S);
}
ISR(WDT_vect) {
@ -44,8 +46,7 @@ ISR(WDT_vect) {
if (counter % 75 == 0) {
shouldSend = true;
}
if (counter >= 225) {
if (!currentState && counter >= 225) {
TinyPower::disableWdt();
counter = 0;
}
}