Skip to content

Commit

Permalink
fix: cancel the existing timer
Browse files Browse the repository at this point in the history
  • Loading branch information
mewejo committed Feb 6, 2023
1 parent c25873e commit 7889ee0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arduino-watering.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ auto timer = timer_create_default();
void setWaterOutletState(int outletIndex, bool state = false) {
if (state) {
WATER_OUTLET_STATES[outletIndex] = LOW;

if (WATER_OUTLET_OFF_TIMERS[outletIndex] != NULL) {
timer.cancel(WATER_OUTLET_OFF_TIMERS[outletIndex]);
}

WATER_OUTLET_OFF_TIMERS[outletIndex] = timer.in(10000, setWaterOutletState, outletIndex);
} else {
WATER_OUTLET_STATES[outletIndex] = HIGH;
Expand Down

0 comments on commit 7889ee0

Please sign in to comment.