This commit is contained in:
Aaro Varis
2026-01-15 10:43:14 +02:00
parent c3276e6f78
commit 8a22f873bd

View File

@@ -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__())