Skip to content

Commit 0560dc6

Browse files
restart and terminate program with physical buttons
1 parent 9b5ae78 commit 0560dc6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

main.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
import machine
44
import time
55

6-
from display import update_display, clear_display, start_display
6+
from display import update_display, clear_display, start_display, display_message
77

88
led = machine.Pin('LED', machine.Pin.OUT)
99

10+
keyA = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_UP)
11+
keyB = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_UP)
12+
1013
led_on = False
1114

1215
def fetch_time():
@@ -35,6 +38,17 @@ def main():
3538
last_time = time.ticks_ms()
3639

3740
while True:
41+
if keyA.value() == 0:
42+
print("Restarting ...")
43+
display_message("Restarting ...", 12)
44+
fetch_time()
45+
46+
if keyB.value() == 0:
47+
led.off()
48+
print("Program has been terminated by the user.")
49+
clear_display()
50+
break
51+
3852
now = time.ticks_ms()
3953
elapsed = time.ticks_diff(now, last_time)
4054

@@ -86,7 +100,7 @@ def main():
86100
current_second += int(fetch_duration)
87101

88102
except Exception as e:
89-
print(f"Error fetching new time: {e}")
103+
print(f"Error fetching new time: {e}")
90104

91105
except ValueError as ve:
92106
led.off()

0 commit comments

Comments
 (0)