Gathered scripts
This commit is contained in:
47
rpi/scripts/timer/main.py
Normal file
47
rpi/scripts/timer/main.py
Normal file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from grove_rgb_lcd import *
|
||||
import led
|
||||
import sys
|
||||
import select
|
||||
|
||||
whiteTime = 5 * 60
|
||||
blackTime = 5 * 60
|
||||
current = "white"
|
||||
|
||||
def compute_seconds(total_seconds):
|
||||
return total_seconds % 60
|
||||
|
||||
def compute_minutes(total_seconds):
|
||||
return total_seconds // 60
|
||||
|
||||
def update_timer(white_total_time, black_total_time):
|
||||
white_minutes = compute_minutes(white_total_time)
|
||||
white_seconds = compute_seconds(white_total_time)
|
||||
|
||||
black_minutes = compute_minutes(black_total_time)
|
||||
black_seconds = compute_seconds(black_total_time)
|
||||
|
||||
setText(f"W {white_minutes:02d}:{white_seconds:02d}\nB {black_minutes:02d}:{black_seconds:02d}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
led.off()
|
||||
led.on()
|
||||
setRGB(255, 255, 255)
|
||||
while whiteTime > 0 and blackTime > 0:
|
||||
currentTime = 0
|
||||
if current == "white":
|
||||
whiteTime -= 1
|
||||
else:
|
||||
blackTime -= 1
|
||||
|
||||
update_timer(whiteTime, blackTime)
|
||||
|
||||
# wait up to 1 second for Enter
|
||||
rlist, _, _ = select.select([sys.stdin], [], [], 1)
|
||||
|
||||
if rlist:
|
||||
sys.stdin.readline() # consume Enter
|
||||
current = "black" if current == "white" else "white"
|
||||
|
||||
led.off()
|
||||
Reference in New Issue
Block a user