-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode_debug.py
More file actions
166 lines (139 loc) · 4.49 KB
/
Copy pathcode_debug.py
File metadata and controls
166 lines (139 loc) · 4.49 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import board
import digitalio
from time import sleep
import lib.TM1637 as tm
import gc
import os
from adafruit_debouncer import Debouncer
# buttons
INPLAY_UP_IN = digitalio.DigitalInOut(board.GP16)
INPLAY_UP_IN.direction = digitalio.Direction.INPUT
INPLAY_UP_IN.pull = digitalio.Pull.UP
INPLAY_UP = Debouncer(INPLAY_UP_IN)
INPLAY_DOWN_IN = digitalio.DigitalInOut(board.GP17)
INPLAY_DOWN_IN.direction = digitalio.Direction.INPUT
INPLAY_DOWN_IN.pull = digitalio.Pull.UP
INPLAY_DOWN = Debouncer(INPLAY_DOWN_IN)
RESET_SCREENS_IN = digitalio.DigitalInOut(board.GP18)
RESET_SCREENS_IN.direction = digitalio.Direction.INPUT
RESET_SCREENS_IN.pull = digitalio.Pull.UP
RESET_SCREENS = Debouncer(RESET_SCREENS_IN)
ADD_RATS_IN = digitalio.DigitalInOut(board.GP19)
ADD_RATS_IN.direction = digitalio.Direction.INPUT
ADD_RATS_IN.pull = digitalio.Pull.UP
ADD_RATS = Debouncer(ADD_RATS_IN)
TOKENS_UP_IN = digitalio.DigitalInOut(board.GP20)
TOKENS_UP_IN.direction = digitalio.Direction.INPUT
TOKENS_UP_IN.pull = digitalio.Pull.UP
TOKENS_UP = Debouncer(TOKENS_UP_IN)
TOKENS_DOWN_IN = digitalio.DigitalInOut(board.GP21)
TOKENS_DOWN_IN.direction = digitalio.Direction.INPUT
TOKENS_DOWN_IN.pull = digitalio.Pull.UP
TOKENS_DOWN = Debouncer(TOKENS_DOWN_IN)
# activity led
ACT_LED = digitalio.DigitalInOut(board.GP22)
ACT_LED.direction = digitalio.Direction.OUTPUT
# screens
INPLAY_SCREEN = tm.TM1637(board.GP0, board.GP1)
TOKEN_SCREEN = tm.TM1637(board.GP14, board.GP15)
# global counts
INPLAY_COUNT = 0
TOKEN_COUNT = 0
# manage global counts
def inplay_up():
global INPLAY_COUNT
INPLAY_COUNT +=1
def inplay_down():
global INPLAY_COUNT
INPLAY_COUNT -=1
def tokens_up():
global TOKEN_COUNT
TOKEN_COUNT +=1
def tokens_down():
global TOKEN_COUNT
TOKEN_COUNT -=1
# write number to screen
def write_screen(screen,value):
try:
screen.number(value)
return "ok"
except:
print("failed to write to screen?")
sleep(1)
# self explanitory
def blank_screen(screen):
try:
screen.number(0000)
return "ok"
except:
print("failed to write to screen?")
sleep(.5)
def blink_act_led():
ACT_LED.value = False
sleep(.5)
ACT_LED.value = True
# add inplay to tokens
def inplay2tokens():
global INPLAY_COUNT
global TOKEN_COUNT
TOKEN_COUNT = (INPLAY_COUNT * 2) - 1
INPLAY_COUNT = TOKEN_COUNT
write_screen(TOKEN_SCREEN, TOKEN_COUNT)
write_screen(INPLAY_SCREEN, TOKEN_COUNT)
blank_screen(INPLAY_SCREEN)
blank_screen(TOKEN_SCREEN)
print(os.uname())
gc.collect()
while True:
INPLAY_UP.update()
if INPLAY_UP.fell:
print("@DEBUG: INPLAY UP")
blink_act_led()
print(f"@DEBUG: INCR INPLAY_COUNT\n {INPLAY_COUNT}")
inplay_up()
print(f"@DEBUG: RESULT INPLAY_COUNT\n {INPLAY_COUNT}")
write_screen(INPLAY_SCREEN, INPLAY_COUNT)
INPLAY_DOWN.update()
if INPLAY_DOWN.fell:
print("\n@DEBUG: INPLAY DOWN")
blink_act_led()
print(f"@DEBUG: DEINCR INPLAY_COUNT \n {INPLAY_COUNT}")
inplay_down()
print(f"@DEBUG: RESULT INPLAY_COUNT\n {INPLAY_COUNT}")
write_screen(INPLAY_SCREEN, INPLAY_COUNT)
TOKENS_UP.update()
if TOKENS_UP.fell:
print("\n@DEBUG: TOKEN UP")
blink_act_led()
print(f"@DEBUG: INCR TOKEN_COUNT\n {TOKEN_COUNT}")
tokens_up()
inplay_up()
print(f"@DEBUG: RESULT TOKEN_COUNT\n {TOKEN_COUNT}")
print(f"@DEBUG: RESULT INPLAY_COUNT\n {INPLAY_COUNT}")
write_screen(TOKEN_SCREEN, TOKEN_COUNT)
write_screen(INPLAY_SCREEN, INPLAY_COUNT)
TOKENS_DOWN.update()
if TOKENS_DOWN.fell:
print("\n@DEBUG: TOKEN DOWN")
blink_act_led()
print(f"@DEBUG: DEINCR TOKEN_COUNT\n {TOKEN_COUNT}")
tokens_down()
inplay_down()
print(f"@DEBUG: RESULT TOKEN_COUNT\n {TOKEN_COUNT}")
print(f"@DEBUG: RESULT INPLAY_COUNT\n {INPLAY_COUNT}")
write_screen(TOKEN_SCREEN, TOKEN_COUNT)
write_screen(INPLAY_SCREEN, INPLAY_COUNT)
RESET_SCREENS.update()
if RESET_SCREENS.fell:
print("\n@DEBUG: RESET")
blink_act_led()
blank_screen(INPLAY_SCREEN)
blank_screen(TOKEN_SCREEN)
INPLAY_COUNT = 0
TOKEN_COUNT = 0
ADD_RATS.update()
if ADD_RATS.fell:
blink_act_led()
print(f"\n@DEBUG: RATS2TOKENS:\nINPLAY:\t{INPLAY_COUNT}\nTOKENS:\t{TOKEN_COUNT}")
inplay2tokens()
print(f"@DEBUG: RATS2TOKENS:\nINPLAY:\t{INPLAY_COUNT}\nTOKENS:\t{TOKEN_COUNT}")