Driver for WS2812
Revision 5:a07522fe36d4, committed 2014-08-18
- Comitter:
- chris
- Date:
- Mon Aug 18 13:25:57 2014 +0000
- Parent:
- 4:b230e85fc5e7
- Commit message:
- Added the ability to write with offsets
Changed in this revision
WS2812.cpp | Show annotated file Show diff for this revision Revisions of this file |
WS2812.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/WS2812.cpp Wed Aug 06 08:34:32 2014 +0000 +++ b/WS2812.cpp Mon Aug 18 13:25:57 2014 +0000 @@ -25,6 +25,25 @@ } +void WS2812::write_offsets(int buf[], int r_offset, int g_offset, int b_offset) +{ + // for each of the data points in the buffer + for (int i = 0; i < __size ; i++) { + + unsigned int argb = 0x0; + // index and extract colour fields from IIRRGGBB buf[] + // 0 = blue, 1 = green, 2 = red, 3 = brightness + argb |= (buf[(i+b_offset)%__size] & 0x000000FF); + argb |= ((buf[(i+g_offset)%__size] & 0x0000FF00)); + argb |= ((buf[(i+r_offset)%__size] & 0x00FF0000)); + argb |= (buf[i] & 0xFF000000); + __write(argb); + } +} + + + + void WS2812::setAll(int colour) { // for each of the data points in the buffer
--- a/WS2812.h Wed Aug 06 08:34:32 2014 +0000 +++ b/WS2812.h Mon Aug 18 13:25:57 2014 +0000 @@ -50,6 +50,7 @@ Reads the temperature register of the LM75B and converts it to a useable value. */ void write (int buf[]); + void write_offsets (int buf[],int r_offset=0, int g_offset=0, int b_offset=0); void setAll(int colour); void useII(int d);