Skip to content
This repository was archived by the owner on Oct 26, 2019. It is now read-only.

Commit efa340e

Browse files
Merge pull request #5 from byWambo/master
Cleaned the code
2 parents 7a4de3b + 28a9d9c commit efa340e

File tree

2 files changed

+10
-67
lines changed

2 files changed

+10
-67
lines changed

Adafruit_WS2801/WS2801.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ def RGB_to_color(r, g, b):
3030
"""
3131
return ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF)
3232

33+
3334
def color_to_RGB(color):
3435
"""Convert a 24-bit color value to 8-bit red, green, blue components.
3536
Will return a 3-tuple with the color component values.
3637
"""
37-
return ((color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF)
38+
return (color >> 16) & 0xFF, (color >> 8) & 0xFF, color & 0xFF
3839

3940

4041
class WS2801Pixels(object):
@@ -46,18 +47,18 @@ def __init__(self, count, clk=None, do=None, spi=None, gpio=None):
4647
(data output) line for software SPI or a spi instance for hardware SPI.
4748
"""
4849
self._spi = None
49-
if spi is not None:
50+
if spi:
5051
# Handle hardware SPI.
5152
self._spi = spi
52-
elif clk is not None and do is not None:
53+
elif clk and do:
5354
# Handle software SPI.
5455
# Default to platform GPIO if not provided.
55-
if gpio is None:
56+
if not gpio:
5657
import Adafruit_GPIO as GPIO
5758
gpio = GPIO.get_platform_gpio()
5859
self._spi = SPI.BitBang(gpio, clk, do, None, None)
5960
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!')
6162
# Setup SPI interface with up to 20mhz speed.
6263
self._spi.set_clock_hz(1000000)
6364
self._spi.set_mode(0)
@@ -92,7 +93,7 @@ def set_pixel_rgb(self, n, r, g, b):
9293
component values. Note you MUST call show() after setting pixels to
9394
see the LEDs change color!
9495
"""
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!'
9697
self._pixels[n*3] = r & 0xFF
9798
self._pixels[n*3+1] = g & 0xFF
9899
self._pixels[n*3+2] = b & 0xFF
@@ -106,8 +107,8 @@ def get_pixel_rgb(self, n):
106107
"""Retrieve the 8-bit red, green, blue component color values of the
107108
specified pixel n. Will return a 3-tuple of red, green, blue data.
108109
"""
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]
111112

112113
def set_pixels(self, color=0):
113114
"""Set all pixels to the provided 24-bit RGB color value. Note you
@@ -128,7 +129,7 @@ def clear(self):
128129
clearing pixels to see the LEDs change!
129130
"""
130131
self.set_pixels(0)
131-
#
132+
132133
# def colorwipe(pixels, c, delay):
133134
# for i in range(len(pixels)):
134135
# setpixelcolor(pixels, i, c)

examples/rainbow.py

-58
This file was deleted.

0 commit comments

Comments
 (0)