EasyManua.ls Logo

Freenove 4WD Smart Car Board for Raspberry Pi - Page 77

Default Icon
132 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Need support? support.freenove.com
73
Chapter 3 Module test (necessary)
www.freenove.com
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
# Intialize the library (must be called once before other functions).
self.strip.begin()
def LED_TYPR(self,order,R_G_B):
B=R_G_B & 255
G=R_G_B >> 8 & 255
R=R_G_B >> 16 & 255
Led_type=["GRB","GBR","RGB", "RBG","BRG","BGR"]
color =
[Color(G,R,B),Color(G,B,R),Color(R,G,B),Color(R,B,G),Color(B,R,G),Color(B,G,R)]
if order in Led_type:
return color[Led_type.index(order)]
def colorWipe(self,strip, color, wait_ms=50):
"""Wipe color across display a pixel at a time."""
color=self.LED_TYPR(self.ORDER,color)
for i in range(self.strip.numPixels()):
self.strip.setPixelColor(i, color)
self.strip.show()
time.sleep(wait_ms/1000.0)
def wheel(self,pos):
"""Generate rainbow colors across 0-255 positions."""
if pos<0 or pos >255:
r=g=b=0
elif pos < 85:
r=pos * 3
g=255 - pos * 3
b=0
elif pos < 170:
pos -= 85
r=255 - pos * 3
g=0
b=pos * 3
else:
pos -= 170
r=0
g=pos * 3
b=255 - pos * 3
return self.LED_TYPR(self.ORDER,Color(r,g,b))
def rainbow(self,strip, wait_ms=20, iterations=1):
"""Draw rainbow that fades across all pixels at once."""
for j in range(256*iterations):
for i in range(self.strip.numPixels()):
self.strip.setPixelColor(i, self.wheel((i+j) & 255))
self.strip.show()
time.sleep(wait_ms/1000.0)