-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathLED_Fader.py
More file actions
68 lines (54 loc) · 1.42 KB
/
Copy pathLED_Fader.py
File metadata and controls
68 lines (54 loc) · 1.42 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
#
# Copyright (C) 2016 by meigrafd (meiraspi@gmail.com) published under the MIT License
#
import pigpio
import time
## CONFIG - START
RED_PIN = 16
GREEN_PIN = 20
BLUE_PIN = 21
STEPS = 1 # number of color changes per step (more is faster, less is slower)
## CONFIG - END
io = pigpio.pi()
def updateColor(color, step):
color += step
if color > 255:
return 255
if color < 0:
return 0
return color
def setLights(pin, brightness):
realBrightness = int(int(brightness) * (float(bright) / 255.0))
io.set_PWM_dutycycle(pin, realBrightness)
bright = 255
R = 255
G = 0
B = 0
setLights(RED_PIN, R)
setLights(GREEN_PIN, G)
setLights(BLUE_PIN, B)
while True:
if R == 255 and G < 255 and B == 0:
G = updateColor(G, STEPS)
setLights(GREEN_PIN, G)
elif R > 0 and G == 255 and B == 0:
R = updateColor(R, -STEPS)
setLights(RED_PIN, R)
elif R == 0 and G == 255 and B < 255:
B = updateColor(B, STEPS)
setLights(BLUE_PIN, B)
elif R == 0 and G > 0 and B == 255:
G = updateColor(G, -STEPS)
setLights(GREEN_PIN, G)
elif R < 255 and G == 0 and B == 255:
R = updateColor(R, STEPS)
setLights(RED_PIN, R)
elif R == 255 and G == 0 and B > 0:
B = updateColor(B, -STEPS)
setLights(BLUE_PIN, B)
setLights(RED_PIN, 0)
setLights(GREEN_PIN, 0)
setLights(BLUE_PIN, 0)
time.sleep(0.5)
io.stop()