@@ -30,11 +30,12 @@ def RGB_to_color(r, g, b):
30
30
"""
31
31
return ((r & 0xFF ) << 16 ) | ((g & 0xFF ) << 8 ) | (b & 0xFF )
32
32
33
+
33
34
def color_to_RGB (color ):
34
35
"""Convert a 24-bit color value to 8-bit red, green, blue components.
35
36
Will return a 3-tuple with the color component values.
36
37
"""
37
- return (( color >> 16 ) & 0xFF , (color >> 8 ) & 0xFF , color & 0xFF )
38
+ return (color >> 16 ) & 0xFF , (color >> 8 ) & 0xFF , color & 0xFF
38
39
39
40
40
41
class WS2801Pixels (object ):
@@ -46,18 +47,18 @@ def __init__(self, count, clk=None, do=None, spi=None, gpio=None):
46
47
(data output) line for software SPI or a spi instance for hardware SPI.
47
48
"""
48
49
self ._spi = None
49
- if spi is not None :
50
+ if spi :
50
51
# Handle hardware SPI.
51
52
self ._spi = spi
52
- elif clk is not None and do is not None :
53
+ elif clk and do :
53
54
# Handle software SPI.
54
55
# Default to platform GPIO if not provided.
55
- if gpio is None :
56
+ if not gpio :
56
57
import Adafruit_GPIO as GPIO
57
58
gpio = GPIO .get_platform_gpio ()
58
59
self ._spi = SPI .BitBang (gpio , clk , do , None , None )
59
60
else :
60
- raise ValueError ('Must specify either spi for for hardware SPI or clk, and do for softwrare SPI!' )
61
+ raise ValueError ('Must specify either spi for for hardware SPI or clk, and do for software SPI!' )
61
62
# Setup SPI interface with up to 20mhz speed.
62
63
self ._spi .set_clock_hz (1000000 )
63
64
self ._spi .set_mode (0 )
@@ -92,7 +93,7 @@ def set_pixel_rgb(self, n, r, g, b):
92
93
component values. Note you MUST call show() after setting pixels to
93
94
see the LEDs change color!
94
95
"""
95
- assert n >= 0 and n < self ._count , 'Pixel n outside the count of pixels!'
96
+ assert 0 <= n < self ._count , 'Pixel n outside the count of pixels!'
96
97
self ._pixels [n * 3 ] = r & 0xFF
97
98
self ._pixels [n * 3 + 1 ] = g & 0xFF
98
99
self ._pixels [n * 3 + 2 ] = b & 0xFF
@@ -106,8 +107,8 @@ def get_pixel_rgb(self, n):
106
107
"""Retrieve the 8-bit red, green, blue component color values of the
107
108
specified pixel n. Will return a 3-tuple of red, green, blue data.
108
109
"""
109
- assert n >= 0 and n < self ._count , 'Pixel n outside the count of pixels!'
110
- return ( self ._pixels [n * 3 ], self ._pixels [n * 3 + 1 ], self ._pixels [n * 3 + 2 ])
110
+ assert 0 <= n < self ._count , 'Pixel n outside the count of pixels!'
111
+ return self ._pixels [n * 3 ], self ._pixels [n * 3 + 1 ], self ._pixels [n * 3 + 2 ]
111
112
112
113
def set_pixels (self , color = 0 ):
113
114
"""Set all pixels to the provided 24-bit RGB color value. Note you
@@ -128,7 +129,7 @@ def clear(self):
128
129
clearing pixels to see the LEDs change!
129
130
"""
130
131
self .set_pixels (0 )
131
- #
132
+
132
133
# def colorwipe(pixels, c, delay):
133
134
# for i in range(len(pixels)):
134
135
# setpixelcolor(pixels, i, c)
0 commit comments