-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimer-720.py
143 lines (125 loc) · 4.3 KB
/
timer-720.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Lock Timer v6
# 720p edition
# DEC 5 2023
# (C) 2017-2023 Matt Burrough
#
# For revised stands with NC switches
# Updated for guizero 1.5.0
from guizero import *
import datetime
import RPi.GPIO as GPIO
seat1Pin = 4
seat2Pin = 17
seat3Pin = 27
seat4Pin = 22
pause = False
seat1Open = 0
seat2Open = 0
seat3Open = 0
seat4Open = 0
openCount = 0
start = datetime.datetime.utcnow()
def custom_format(td):
minutes, seconds = divmod(td.seconds, 60)
hours, minutes = divmod(minutes, 60)
seconds += td.microseconds / 1e6
return '{:02d}:{:02d}:{:05.2f}'.format(hours, minutes, seconds)
def stop():
global pause
pause = True
def reset():
global pause
global start
global seat1Open
global seat2Open
global seat3Open
global seat4Open
global openCount
timeLbl.value = "00:00:00.00"
seat1Time.value = "LOCKED"
seat2Time.value = "LOCKED"
seat3Time.value = "LOCKED"
seat4Time.value = "LOCKED"
seat1Open = 0
seat2Open = 0
seat3Open = 0
seat4Open = 0
openCount = 0
pause = False
start = datetime.datetime.utcnow()
timeLbl.after(10, update_time)
def update_time():
global seat1Open
global seat2Open
global seat3Open
global seat4Open
now = datetime.datetime.utcnow()
checkLocks()
elapsed = now - start
timeLbl.value = custom_format(elapsed)
if(seat1Open == 1):
seat1Time.value = custom_format(elapsed)
seat1Open = 2
if(seat2Open == 1):
seat2Time.value = custom_format(elapsed)
seat2Open = 2
if(seat3Open == 1):
seat3Time.value = custom_format(elapsed)
seat3Open = 2
if(seat4Open == 1):
seat4Time.value = custom_format(elapsed)
seat4Open = 2
if(openCount >= 4):
stop()
if(pause != True):
timeLbl.after(10, update_time)
def readPin(pinnum):
return GPIO.input(pinnum)
def configPin(pinnum):
total = pinnum + 1
GPIO.setup(pinnum, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
def checkLocks():
global seat1Open
global seat2Open
global seat3Open
global seat4Open
global openCount
if(readPin(seat1Pin) == 1 and seat1Open < 1):
openCount += 1
seat1Open = 1
if(readPin(seat2Pin) == 1 and seat2Open < 1):
openCount += 1
seat2Open = 1
if(readPin(seat3Pin) == 1 and seat3Open < 1):
openCount += 1
seat3Open = 1
if(readPin(seat4Pin) == 1 and seat4Open < 1):
openCount += 1
seat4Open = 1
# Main
GPIO.setmode(GPIO.BCM)
configPin(seat1Pin)
configPin(seat2Pin)
configPin(seat3Pin)
configPin(seat4Pin)
app = App(title="Lockpick Village Timer", width=1280, height=720)
title = Text(app, text="Lockpick Village Timed Challenge", size=64, font="Arial", color="darkblue")
timeLbl = Text(app, text="00:00:00.00", size=72, font="Arial", color="darkred")
box = Box(app, layout="grid")
seat1 = Text(box, text="Seat 1", size=48, font="Arial", color="darkblue", grid=[0,0], align="top")
seat2 = Text(box, text="Seat 2", size=48, font="Arial", color="darkblue", grid=[2,0], align="top")
seat1Time = Text(box, text="LOCKED", size=48, font="Arial", color="black", grid=[0,1], align="top")
space1 = Text(box, text=" ", size=48, font="Arial", color="black", grid=[1,1], align="top")
seat2Time = Text(box, text="LOCKED", size=48, font="Arial", color="black", grid=[2,1], align="top")
space2 = Text(box, text=" ", size=48, font="Arial", color="black", grid=[0,2], align="top")
seat3 = Text(box, text="Seat 3", size=48, font="Arial", color="darkblue", grid=[0,3], align="top")
seat4 = Text(box, text="Seat 4", size=48, font="Arial", color="darkblue", grid=[2,3], align="top")
seat3Time = Text(box, text="LOCKED", size=48, font="Arial", color="black", grid=[0,4], align="top")
space3 = Text(box, text=" ", size=48, font="Arial", color="black", grid=[1,4], align="top")
seat4Time = Text(box, text="LOCKED", size=48, font="Arial", color="black", grid=[2,4], align="top")
btnStop = PushButton(box, text="Stop", command=stop, grid=[0,5], align="top")
btnReset = PushButton(box, text="Reset + Go", command=reset, grid=[2,5], align="top")
timeLbl.after(10, update_time)
start = datetime.datetime.utcnow()
app.display()
GPIO.cleanup()