Refactor relay state handling to use a dedicated method and update last button press time on LCD
This commit is contained in:
5
init.py
5
init.py
@@ -38,6 +38,9 @@ class AlarmClock:
|
||||
while True:
|
||||
self.loop()
|
||||
|
||||
def setRelayState(self, state: bool):
|
||||
self.relayGpio.write(1 if state else 0)
|
||||
|
||||
def loop(self):
|
||||
currentButtonState = not self.buttonGpio.read()
|
||||
if currentButtonState != self.lastKnownButtonState:
|
||||
@@ -49,7 +52,7 @@ class AlarmClock:
|
||||
print(f"Button '{button}' pressed state: {state}")
|
||||
if button == "button":
|
||||
self.lastButtonPressTime = time()
|
||||
self.relayGpio.write(1 if state else 0)
|
||||
self.setRelayState(not self.relayGpio.read())
|
||||
self.setLcdText(self.lastButtonPressTime.__str__())
|
||||
|
||||
def setLcdText(self, text: str):
|
||||
|
||||
Reference in New Issue
Block a user