-
Notifications
You must be signed in to change notification settings - Fork 0
/
ledstrip.py
126 lines (107 loc) · 1.94 KB
/
ledstrip.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python
import time
import RPi.GPIO as GPIO
CLK=11
DAT=12
debug=False;
delay=0
def init():
GPIO.setwarnings(debug)
GPIO.setmode(GPIO.BOARD)
GPIO.setup(CLK, GPIO.OUT)
GPIO.setup(DAT, GPIO.OUT)
def cleanup():
GPIO.cleanup()
def Clock():
GPIO.output(CLK,False)
time.sleep(delay)
GPIO.output(CLK,True)
time.sleep(delay)
def Send32Zero():
for x in range(32):
GPIO.output(DAT,False)
if (debug):
print "0",
Clock()
def getCode(dat):
tmp=0
if ((dat & 0x80) == 0):
tmp |= 0x02
if ((dat & 0x40) == 0):
tmp|= 0x01
# print "Get Code [%d] %s : %s" % (dat, tmp, bin(dat))
return tmp
def SetColor( Red, Green, Blue):
dx =0
# print bin(dx)
dx |= 0x03 << 30
# print bin(dx)
dx |= getCode(Blue)
# print bin(dx)
dx |= getCode(Green)
# print bin(dx)
dx |= getCode(Red)
# print bin(dx)
dx |= Blue <<16
# print bin(dx)
dx |= Green <<8
# print bin(dx)
dx |= Red
if (debug):
print bin(dx)
Send(dx)
def Send(dx):
if (debug):
print "Sending [%s]" % (bin (dx))
Send32Zero()
for x in range(32):
if ((dx & 0x80000000) != 0 ):
GPIO.output(DAT,True)
if (debug):
print "1",
else:
GPIO.output(DAT,False)
if( debug):
print "0",
dx <<= 1
Clock()
if (debug):
print ""
Send32Zero()
print "Init:"
init()
print "All 0"
SetColor(0,0,0)
#time.sleep(1)
print "All 255"
SetColor(255,255,255)
time.sleep(.2)
print "Red 255"
SetColor(255,0,0)
time.sleep(.2)
print "Green 255"
SetColor(0,255,0)
time.sleep(.2)
print "Blue 255"
SetColor(0,0,255)
time.sleep(.2)
print "All 0"
SetColor(0,0,0)
time.sleep(.2)
for z in range (10):
for x in range(255):
#print "X:%d" % (x)
#y=x*10
SetColor(x,x,x)
for x in range(255):
SetColor(255-x,255-x,255-x)
for x in range(20):
SetColor(255,0,0)
time.sleep(0.1)
SetColor(0,0,255)
time.sleep(0.1)
print "All 0"
SetColor(0,0,0)
#time.sleep(1)
print "Cleanup"
cleanup()