-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_scoreboards_1.py
executable file
·52 lines (42 loc) · 1.08 KB
/
test_scoreboards_1.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
#!/usr/bin/python
# coding: utf8
import pigpio
import time
import button
import teamscore
import math
import logging
logging.basicConfig(level=logging.DEBUG,format='%(levelname)s:%(threadName)s:%(message)s')
last=0
# Create a pigpio object and a max7219 object
pi=pigpio.pi()
score=teamscore.TeamScore(pi, clock=22, data=27, load=24)
score.wakeup()
value=0
# Test callback function
def test(gpio, level, tick, butnum):
global last, score, value
if level==1:
state="released"
else:
state="pushed "
if butnum==1: value+=1
else: value-=1
value=value%100
score.scoreCorrect(value)
s=tick-last
last=tick
print "Button %d %s at tick: %d (ellapsed: %d). Newvalue %d" % (butnum, state, tick, s, value)
# Create 2 buttons
a = button.Button(pi=pi, gpio=7, callback=test, args=[1])
b = button.Button(pi=pi, gpio=8, callback=test, args=[2])
# Start an infinite loop, and wait for button events
print "Starting main loop"
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("Keyboard interrupt")
finally:
print("Running finally cleanup code")
pi.stop