-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLED.py
53 lines (40 loc) · 1.08 KB
/
LED.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
52
try:
import RPi.GPIO as GPIO
except ImportError:
import GPIO_dummy as GPIO
from BitShifter import BitShifter
from threading import Timer
NUMBER_OF_LEDS = 8
array = BitShifter()
class CountDown:
def __init__(self):
self.cnt = NUMBER_OF_LEDS-1
array.set_all(GPIO.HIGH)
def tick(self):
self.cnt -= 1
array.set(self.cnt, GPIO.LOW)
class BlinkAll:
def __init__(self, times, interval):
self.times = times
self.on = True
self.interval = interval
self.cancelled = False
array.set_all(GPIO.HIGH)
self.t = Timer(self.interval, self.tick)
def tick(self):
if self.cancelled is True:
array.set_all(GPIO.LOW)
return
if self.on:
self.times -= 1
if self.times == 0:
return
array.set_all(GPIO.LOW)
self.on = False
else:
array.set_all(GPIO.HIGH)
self.on = True
t = Timer(self.interval, self.tick)
t.start()
def cancel(self):
self.cancelled = True