-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGiftLightPad.py
36 lines (31 loc) · 1.05 KB
/
GiftLightPad.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
from threading import Timer
class GiftLightPad:
def __init__(self, orchestrator):
self.led = orchestrator.led
self.orchestrator = orchestrator
self.active = False
self.value = -1
def set_value(self, value):
self.value = value
if self.active:
if value == 1:
print("gift is present")
t1 = Timer(1.0, self.timer,(value, 0))
t1.start()
if value == 0:
print("Gift removed")
self.orchestrator.gift_removed()
def timer(self, value, led_id):
if value != self.value:
self.led.set_rgb("0,0,0")
else:
if self.active:
self.led.set_rgb("0,255,0",led_id)
if led_id != 2:
t_next = Timer(1.0, self.timer,(value, led_id+1))
t_next.start()
else:
print("Woop woop, gift placed!")
self.active = False
self.orchestrator.gift_placed()
return