Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setPixelColors func for LED control #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions Code/Server/Led.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ def LED_TYPR(self,order,R_G_B):
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 setPixelColors(self, pixelColors):
"""
Sets the color of specific Pixel LEDs (0-7).
The pixels are specified with their respective color
in a sequence of tupels (pixelIndex, color).
"""
for pixel, color in pixelColors:
if pixel < 0 or pixel >= self.strip.numPixels():
continue
color=self.LED_TYPR(self.ORDER,color)
self.strip.setPixelColor(pixel, color)
self.strip.show()

def colorWipe(self,strip, color, wait_ms=50):
"""Wipe color across display a pixel at a time."""
color=self.LED_TYPR(self.ORDER,color)
Expand Down Expand Up @@ -127,6 +141,13 @@ def ledMode(self,n):
print ('Program is starting ... ')
try:
while True:
print ("Color pattern")
led.setPixelColors([
(0, Color(0 ,0, 0)), (1, Color(0 ,0, 255)),
(2, Color(0 ,255, 0)), (3, Color(0 ,255, 255)),
(4, Color(255 ,0, 0)), (5, Color(255 ,0, 255)),
(6, Color(255 ,255, 0)), (7, Color(255 ,255, 255)) ])
time.sleep(1)
print ("Chaser animation")
led.colorWipe(led.strip, Color(255,0, 0)) # Red wipe
led.colorWipe(led.strip, Color(0, 255, 0)) # Green wipe
Expand All @@ -138,13 +159,3 @@ def ledMode(self,n):
led.colorWipe(led.strip, Color(0,0,0),10)
except KeyboardInterrupt: # When 'Ctrl+C' is pressed, the child program destroy() will be executed.
led.colorWipe(led.strip, Color(0,0,0),10)