diff options
author | misterdanb <danb@hasi.it> | 2016-03-28 01:58:14 +0200 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-05-19 22:29:11 +0300 |
commit | a0a08b4be1583aa7a4ef33d3b1b0aa6553732eca (patch) | |
tree | 278812b070128898c4afade05b0781a622bb515f /esp8266/scripts | |
parent | 6fa60153eae746bee4657ae3fcd69e71144c6d59 (diff) | |
download | micropython-a0a08b4be1583aa7a4ef33d3b1b0aa6553732eca.tar.gz micropython-a0a08b4be1583aa7a4ef33d3b1b0aa6553732eca.zip |
esp8266: Add APA102 serial individually controllable LEDs support.
APA102 is a new "smart LED", similar to WS2812 aka "Neopixel".
Diffstat (limited to 'esp8266/scripts')
-rw-r--r-- | esp8266/scripts/apa102.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/esp8266/scripts/apa102.py b/esp8266/scripts/apa102.py new file mode 100644 index 0000000000..126448cc20 --- /dev/null +++ b/esp8266/scripts/apa102.py @@ -0,0 +1,28 @@ +# APA102 driver for MicroPython on ESP8266 +# MIT license; Copyright (c) 2016 Robert Foss, Daniel Busch + +from esp import apa102_write + +class APA102: + def __init__(self, clock_pin, data_pin, n): + self.clock_pin = clock_pin + self.data_pin = data_pin + self.n = n + self.buf = bytearray(n * 4) + + self.clock_pin.init(clock_pin.OUT) + self.data_pin.init(data_pin.OUT) + + def __setitem__(self, index, val): + r, g, b, brightness = val + self.buf[index * 4] = r + self.buf[index * 4 + 1] = g + self.buf[index * 4 + 2] = b + self.buf[index * 4 + 3] = brightness + + def __getitem__(self, index): + i = index * 4 + return self.buf[i], self.buf[i + 1], self.buf[i + 2], self.buf[i + 3] + + def write(self): + apa102_write(self.clock_pin, self.data_pin, self.buf) |