From 8a22f873bd8abfe2b9b4c0a118e0699ac70ae050 Mon Sep 17 00:00:00 2001 From: Aaro Varis Date: Thu, 15 Jan 2026 10:43:14 +0200 Subject: [PATCH] a --- init.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/init.py b/init.py index 73d8635..8125857 100644 --- a/init.py +++ b/init.py @@ -21,12 +21,14 @@ def isSunUp() -> bool: class AlarmClock: ledGpio: GPIO buttonGpio: GPIO + relayGpio: GPIO lastKnownButtonState: bool = False lcd: JHD1802 lastButtonPressTime: float = 0.0 def __init__(self, pins: dict = {}): self.ledGpio = GPIO(pins.get("led", 5), GPIO.OUT) self.buttonGpio = GPIO(pins.get("button", 6), GPIO.IN) + self.relayGpio = GPIO(pins.get("relay", 16), GPIO.OUT) self.lcd = JHD1802() self.setLcdText("AlarmClock Init") @@ -40,12 +42,11 @@ class AlarmClock: currentButtonState = not self.buttonGpio.read() if currentButtonState != self.lastKnownButtonState: self.lastKnownButtonState = currentButtonState - if currentButtonState: - self.onButtonPress("button") + self.onButtonPress("button", currentButtonState) - def onButtonPress(self, button: str): - print(f"Button {button} pressed") + def onButtonPress(self, button: str, state: bool): + print(f"Button '{button}' pressed state: {state}") if button == "button": self.lastButtonPressTime = time() self.setLcdText(self.lastButtonPressTime.__str__())