when window is opened, continue to send state every 10 mins until it is
closed
This commit is contained in:
parent
a84afeea61
commit
dd3a05889d
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user