forked from tinue/apa102-pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
basecolorcycle.py
executable file
·56 lines (48 loc) · 1.45 KB
/
basecolorcycle.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
53
54
55
56
import apa102
import time
"""
This class is the basis of all color cycles, such as rainbow or theater chase.
"""
class BaseColorCycle:
def __init__(self, numLEDs, pauseValue = 0, globalBrightness = 31): # Init method
self.numLEDs = numLEDs
self.pauseValuse = pauseValue
self.globalBrightness = globalBrightness
timeOfLastCall = 0
cycleCounter = 0
"""
void init()
This method is called to initialize a color program.
"""
def init(self):
# The default does nothing. A particular subclass could e.g. light all LEDs to white.
print('Init')
"""
void shutdown()
This method is called at the end, when the light program shoule terminate
"""
def shutdown(self):
# The default does nothing
print('Shutdown')
"""
void update()
This method paints one cycle. It must be implemented
"""
def update(self):
raise NotImplementedError("Please implement the update() method")
"""
Start the actual work
"""
try:
strip = apa102.APA102(numPixels, globalBrightness) # Low brightness (2 out of max. 31)
while True: # Loop forever
cycleCounter += 1
update()
strip.show()
time.sleep(pauseValue)
except KeyboardInterrupt: # Abbruch...
print('Interrupted...')
strip.clearStrip()
print('Strip cleared')
strip.cleanup()
print('SPI closed')