Created
December 21, 2020 13:29
-
-
Save andywarburton/14f4737b6699a114c9ca90efcb0eb52c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import board | |
from adafruit_ht16k33.segments import BigSeg7x4 | |
import time | |
import touchio | |
# setup the 7 segment display | |
i2c = board.I2C() | |
display = BigSeg7x4(i2c) | |
display.brightness = 0.2 | |
# configure the touch stuff | |
touch1 = touchio.TouchIn(board.A3) | |
touch1.threshold = 2000 | |
touch2 = touchio.TouchIn(board.A1) | |
touch2.threshold = 2000 | |
# set variables | |
timer = 0 | |
status = "waiting" | |
while True: | |
print("------") | |
print("DEBUG") | |
print("STATUS: ", status) | |
print("TOUCH1: ", touch1.raw_value, touch1.value) | |
print("TOUCH2: ", touch2.raw_value, touch2.value) | |
if(timer > 0): | |
print("TIMER: ", timer) | |
if status == "waiting": | |
display.print("00:00") | |
timer = 0 | |
if touch1.value and touch2.value: | |
display.print("--:--") | |
status = "ready" | |
if status == "ready": | |
# buttons released | |
if not touch1.value and not touch2.value: | |
status = "counter" | |
display.fill(0) | |
if status == "counter": | |
if touch1.value and touch2.value: | |
status = "finished" | |
else: | |
timerstr = str(round(timer,2)).replace(".", "", 1) | |
print(timerstr) | |
display.fill(0) | |
display.ampm = True | |
display.print(timerstr) | |
time.sleep(0.1) | |
timer += 0.1 | |
if(status == "finished"): | |
for _ in range(15): | |
display.fill(0) | |
time.sleep(0.3) | |
display.ampm = True | |
display.print(timerstr) | |
time.sleep(0.3) | |
print("------------------------") | |
print("FINAL TIME") | |
print(timer) | |
print("------------------------") | |
status = "waiting" | |
time.sleep(5) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment