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

10
init.py
View File

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