-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrgbtext.py
executable file
·43 lines (32 loc) · 1.27 KB
/
rgbtext.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
#!/usr/bin/python
from ledStrip import ledstrip
import argparse
import time
# Define app description and optional parameters
parser = argparse.ArgumentParser(description = 'Example sketch that controls an LED strip via Spacesb. It uses the LED Strip Python library for Adafruit\'s LPD8806 LED strips.')
# Define the led strip length optional parameter
parser.add_argument('-l', '--leds', '--pixels',
nargs = 1, type = int, default = 32,
help = 'Length of led strip leds or pixels')
# Read all command line parameters
args = parser.parse_args()
def main():
# initialize spi and leds objects
spidev = file("/dev/spidev0.0", "wb") # ref to spi connection to the led bar
leds = ledstrip.LEDStrip(pixels=args.leds, spi=spidev)
turn_off(leds)
while True:
ured, ugreen, ublue = raw_input( "Enter RGB values (x to exit): ").split()
if ured == 'x':
break
for i in range(32):
leds.setPixelColorRGB(pixel = i, red = int(ured), green = int(ugreen), blue = int(ublue))
leds.show()
time.sleep(3)
turn_off(leds)
def turn_off(leds):
for each in range(32):
leds.setPixelColorRGB(pixel = each, red = 0, green = 0, blue = 0)
leds.show()
if __name__ == "__main__":
main()