diff --git a/stopwatch.py b/stopwatch.py new file mode 100644 index 0000000000000000000000000000000000000000..1f1e9e7e73ab061ea6af21489c0dd0b9e93eed22 --- /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")