-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathpushbuttontest.py
41 lines (32 loc) · 1.29 KB
/
pushbuttontest.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
# pushbuttontest.py Demonstrates the pushbutton library
# Author: Peter Hinch
# V1.02 6th Sep 2014
from usched import Sched, wait
from pushbutton import Pushbutton, descriptor
def stop(fTim, objSch): # Stop the scheduler after fTim seconds
yield from wait(fTim)
objSch.stop()
def x5print(*args):
print("X5 released " +args[0]) # Demo of argument passing
def x6print(*args):
print("X6 pressed " + args[0])
def yellowlong(*args):
print(args[0] +" yellow")
def yellowdbl(*args):
print(args[0] +" yellow")
def test(duration = 0): # responds to switches
if duration:
print("Tests pushbuttons for {:5d} seconds".format(duration))
else:
print("Tests pushbuttons")
objSched = Sched()
Pushbutton(objSched, 'X5', descriptor,
false_func = x5print, false_func_args = ("Red",)) # X5 triggers on open
Pushbutton(objSched, 'X6', descriptor,
true_func = x6print, true_func_args = ("Yellow",),
long_func = yellowlong, long_func_args = ("Long press",),
double_func = yellowdbl, double_func_args = ("Double click",)) # X6 triggers on close
if duration:
objSched.add_thread(stop(duration, objSched))
objSched.run()
test(20)