A version of library with explicit flush() .
Fork of Chainable_RGB_LED by
Revision 2:d827cd87b212, committed 2018-08-26
- Comitter:
- bor2
- Date:
- Sun Aug 26 00:29:00 2018 +0000
- Parent:
- 1:50d0a66599e1
- Commit message:
- Addressing problems that some B and G colors are swapped and some segments are powered by several strips.; ; Note this code doesn't compile in Eclipse and I'd like to figure out why.
Changed in this revision
ChainableLED.cpp | Show annotated file Show diff for this revision Revisions of this file |
ChainableLED.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 50d0a66599e1 -r d827cd87b212 ChainableLED.cpp --- a/ChainableLED.cpp Sun May 03 01:34:41 2015 +0000 +++ b/ChainableLED.cpp Sun Aug 26 00:29:00 2018 +0000 @@ -75,6 +75,7 @@ for (uint8_t i=0; i<_num_leds; i++) { setColorRGB(i, 0, 0, 0); } + flush(); } void ChainableLED::sendByte(uint8_t b) @@ -103,6 +104,12 @@ void ChainableLED::setColorRGB(uint32_t led, uint8_t red, uint8_t green, uint8_t blue) { + _leds->rgb[led*3 + 0] = red; + _leds->rgb[led*3 + 1] = green; + _leds->rgb[led*3 + 2] = blue; +} + +void ChainableLED::flush() { // Send data frame prefix (32x "0") sendByte(0x00); sendByte(0x00); @@ -110,12 +117,7 @@ sendByte(0x00); // Send color data for each one of the leds - for (uint8_t i=0; i<_num_leds; i++) { - if (i == led) { - _leds->rgb[i*3 + 0] = red; - _leds->rgb[i*3 + 1] = green; - _leds->rgb[i*3 + 2] = blue; - } + for (uint32_t i=0; i<_num_leds; i++) { sendColor(_leds->rgb[i*3 + 0], _leds->rgb[i*3 + 1], _leds->rgb[i*3 + 2]); } @@ -154,4 +156,5 @@ } setColorRGB(led, (uint8_t)(255.0f*r), (uint8_t)(255.0f*g), (uint8_t)(255.0f*b)); + flush(); }
diff -r 50d0a66599e1 -r d827cd87b212 ChainableLED.h --- a/ChainableLED.h Sun May 03 01:34:41 2015 +0000 +++ b/ChainableLED.h Sun Aug 26 00:29:00 2018 +0000 @@ -43,6 +43,7 @@ void setColorRGB(uint32_t led, uint8_t red, uint8_t green, uint8_t blue); void setColorHSB(uint32_t led, float hue, float saturation, float brightness); + void flush(); void ledsOff(void); private: