Closed schelmo closed 5 years ago
@kevinjwalters heya i think you wrote the original code, want to test this adjustment?
Sure, I'm away from LEDs at the moment but can test this in the latter part of next week.
The code change makes sense wrt setting data before the clock pulse rises. I've just tested and PR code runs and produces expected colours whereas existing code is buggy wrt colours when non-hardware assisted pins are used.
In detail, on a CPX (M0 based) running 4.0.0 rc1 with library from a recent bundle using a string of 50 "generic" WS2801 on SCL (A4) & SDA (A5):
>>> import adafruit_ws2801
>>> import board
>>> p = adafruit_ws2801.WS2801(board.SCL, board.SDA, 50, brightness=1.0)
>>> p[0:3] = [(5,0,0)] *3
>>> p[99] = (5,0,0)
>>> p[59] = (5,0,0)
>>> p[49] = (5,0,0)
>>> p[50] = (5,0,0)
>>> p[49] = (0,0,5)
>>> type(p._spi)
<class 'SPI'>
Output is as expected and hardware is being used.
Changing pins to A2 for clock and A3 for data to force a bitbang approach from library:
>>> import adafruit_ws2801
>>> import board
>>> p = adafruit_ws2801.WS2801(board.A2, board.A3, 50, brightness=1.0)
>>> type(p._spi)
<class 'NoneType'>
>>> print("this is with library without #4")
this is with library without #4
>>> p[0:3] = [(5,0,0)] *3 ### first three green, not red!
>>> p[0:5] = [(0,5,0)] *5 ### first five blue, not green!
>>> p[0:5] = [(0,0,5)] *5 ### 1st blue, 2nd-5th pink (magenta?), 6th red
>>> p[0:5] = [(0,0,5)] *5
>>> p[0:5] = [(0,0,5)] *5
>>> p[0:5] = [(0,0,5)] *5 ### no change
And now with the new library from this PR (note file is temporary name of adafruit_ws2801_pr4.py
):
>>> import adafruit_ws2801_pr4
>>> import board
>>> p = adafruit_ws2801_pr4.WS2801(board.A2, board.A3, 50, brightness=1.0)
>>> type(p._spi)
<class 'NoneType'>
>>> p[0:5] = [(5,0,0)] *5
>>> p[0:5] = [(0,5,0)] *5
>>> p[0:5] = [(0,0,5)] *5
>>> p[0:5] = [(0,0,2)] *5
>>> p[0:5] = [(0,0,1)] *5
>>> p[0:50] = [(0,0,1)] *50
>>> p[0:50] = [(1,0,0)] *50
>>> p[0:50] = [(0,0,0)] *50
All RGB LEDs as expected, i.e. correct colours.
(Note: for anyone unfamiliar with WS2801, first LED often changes colour rather randomly if clock/data are not connected to anything or are being connected manually to a circuit.)
.. else i get weird colors for two different strips