optimize state reading in wdt, reset wdt counter when interrupting

This commit is contained in:
Nicu Hodos 2018-07-15 23:56:37 +02:00
parent 534039dc08
commit 2508d2cf5e
2 changed files with 11 additions and 7 deletions

View File

@ -8,7 +8,7 @@
ContactSensor sensor = ContactSensor(WINDOW1, SENDER);
int counter = 0;
volatile int counter = 0;
bool currentState;
void setup() {
@ -40,14 +40,16 @@ byte readState() {
ISR(PCINT0_vect) {
sensor.sendStateAndVoltage(readState());
wdt_reset();
counter = 0;
}
ISR(WDT_vect) {
bool state = readState();
if (state != currentState) {
sensor.sendStateAndVoltage(readState());
updateState();
return;
sensor.sendStateAndVoltage(state);
currentState = state;
return;
}
counter++;
if (counter % 225 == 0) {

View File

@ -7,7 +7,7 @@
ContactSensor sensor = ContactSensor(WINDOW2, SENDER);
int counter = 0;
volatile int counter = 0;
bool currentState;
void setup() {
@ -37,13 +37,15 @@ byte readState() {
ISR(PCINT0_vect) {
sensor.sendStateAndVoltage(readState());
wdt_reset();
counter = 0;
}
ISR(WDT_vect) {
bool state = readState();
if (state != currentState) {
sensor.sendStateAndVoltage(readState());
updateState();
sensor.sendStateAndVoltage(state);
currentState = state;
return;
}
counter++;