This commit is contained in:
Aaro Varis
2026-01-15 10:29:53 +02:00
parent de991db055
commit 390388329f

20
init.py
View File

@@ -25,14 +25,19 @@ class AlarmClock:
self.ledGpio = GPIO(pins.get("led", 5), GPIO.OUT)
self.buttonGpio = GPIO(pins.get("button", 6), GPIO.IN)
def loop(self):
def start(self):
print("AlarmClock started")
while True:
currentButtonState = self.buttonGpio.read()
if currentButtonState != self.lastKnownButtonState:
self.lastKnownButtonState = currentButtonState
if currentButtonState:
self.onButtonPress("button")
time.sleep(0.05)
self.loop()
def loop(self):
currentButtonState = self.buttonGpio.read()
if currentButtonState != self.lastKnownButtonState:
self.lastKnownButtonState = currentButtonState
if currentButtonState:
self.onButtonPress("button")
def onButtonPress(self, button: str):
print(f"Button {button} pressed")
@@ -50,6 +55,7 @@ pins = {
"buzzer": 12,
}
alarm_clock = AlarmClock(pins)
alarm_clock.start()