m
This commit is contained in:
10
init.py
10
init.py
@@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user