Skip to content

Commit 45fde04

Browse files
committed
read button only once
1 parent 25060da commit 45fde04

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/OpenBikeSensorFirmware.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,14 @@ static void powerKeepAliveTimerISR()
240240
if(shutdownState == 0)
241241
{
242242
unsigned long timeSinceLastPowerKeepAlive = millis() - timeOfLastPowerKeepAlive;
243-
if(!digitalRead(IP5306_BUTTON) && timeSinceLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS)
243+
bool ip5306ButtonState = digitalRead(IP5306_BUTTON);
244+
245+
if(!ip5306ButtonState && timeSinceLastPowerKeepAlive > POWER_KEEP_ALIVE_INTERVAL_MS)
244246
{
245247
timeOfLastPowerKeepAlive = millis();
246248
digitalWrite(IP5306_BUTTON, HIGH);
247249
}
248-
else if(digitalRead(IP5306_BUTTON) && timeSinceLastPowerKeepAlive > 300)
250+
else if(ip5306ButtonState && timeSinceLastPowerKeepAlive > 300)
249251
{
250252
timeOfLastPowerKeepAlive = millis();
251253
digitalWrite(IP5306_BUTTON, LOW);

0 commit comments

Comments
 (0)