]> vault307.fbx.one Git - lcdTracker.git/blob - lcdToken.py
token board using LCD
[lcdTracker.git] / lcdToken.py
1 import machine, time, random
2 import groveLCD as lcd
3
4 global count
5 count=0
6
7 def updateDisplay():
8 lcd.setText_norefresh("Number of stamps\n %d" %count)
9
10 lcd.setRGB(50,0,50)
11 lcd.clearText()
12 lcd.setText_norefresh("Hello Marcus!")
13 time.sleep(2)
14 updateDisplay()
15
16 btnP=machine.Pin(15,machine.Pin.IN,machine.Pin.PULL_UP)
17 btnD=machine.Pin(16,machine.Pin.IN,machine.Pin.PULL_UP)
18
19 global btnP_pressed
20 btnP_pressed=False
21
22 global btnD_pressed
23 btnD_pressed=False
24
25 # button handlers (interrupts)
26 def btn_reader(pin):
27 btn=pin
28 while True:
29 if btnP.value()==0:
30 btnP_pressed=True
31 increment()
32 time.sleep(0.5)
33 btnP_pressed=False
34 elif btnD.value()==0:
35 btnD_pressed=True
36 decrement()
37 time.sleep(0.5)
38 btnD_pressed=False
39
40 def increment():
41 global count
42 count+=1
43 global r
44 global g
45 global b
46 r=0
47 g=0
48 b=0
49 def setR():
50 global r
51 r=random.randrange(50)
52 return r
53 def setG():
54 global g
55 g=random.randrange(50)
56 return g
57 def setB():
58 b=random.randrange(50)
59 return b
60 if (count%10)==0:
61 setR();setG();setB()
62 lcd.setRGB(r,g,b)
63 lcd.setText("Good Job Marcus!\n Pick a prize")
64 time.sleep(3)
65 lcd.setRGB(50,0,50)
66 updateDisplay()
67 return count
68
69 def decrement():
70 global count
71 count-=1
72 updateDisplay()
73 return count
74
75 btnP.irq(trigger=machine.Pin.IRQ_FALLING,handler=btn_reader(btnP))
76 btnD.irq(trigger=machine.Pin.IRQ_FALLING,handler=btn_reader(btnD))
77
78 # TODO put special surprise if reach "full" board <66>