diff --git a/init.py b/init.py index 7bc9a34..d668697 100644 --- a/init.py +++ b/init.py @@ -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()