From ac36e25b8c46d28628666a9572c5a1040c9a894c Mon Sep 17 00:00:00 2001 From: ef1g21 <ef1g21@soton.ac.uk> Date: Mon, 15 May 2023 02:22:29 +0000 Subject: [PATCH] Upload New File --- stopwatch.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 stopwatch.py diff --git a/stopwatch.py b/stopwatch.py new file mode 100644 index 0000000..1f1e9e7 --- /dev/null +++ b/stopwatch.py @@ -0,0 +1,30 @@ +import machine +import utime + +start = machine.Pin(20, machine.Pin.IN, machine.Pin.PULL_UP) +stop = machine.Pin(21, machine.Pin.IN, machine.Pin.PULL_UP) +buzzer_pin = machine.Pin(18, machine.Pin.OUT) + + +while True: + + while start.value() == 1: + utime.sleep_ms(10) + startTime = utime.ticks_ms() + + print("Start timer") + + + while stop.value() == 1: + utime.sleep_ms(10) + stopTime = utime.ticks_ms() + buzzer_pin.value(1) + utime.sleep(0.5) + buzzer_pin.value(0) + + print("Timer stopped") + + + time = stopTime - startTime + timeInSecs = time / 1000 + print("Stopwatch time:", timeInSecs, "s") -- GitLab