Library for LPD8806 (and probably LPD8803/LPD8809) PWM LED driver chips, strips and pixels. Standard connected to 1st hardware SPI module. Data -> p5 and Clock -> p7 use a fixed sized buffer rather than malloc - if we use malloc rtos is unhappy...
Fork of LPD8806 by
Diff: LPD8806.cpp
- Revision:
- 2:5d654eba3240
- Parent:
- 1:6ebd3ac910b6
--- a/LPD8806.cpp Fri Dec 16 10:26:35 2011 +0000 +++ b/LPD8806.cpp Fri May 30 03:37:16 2014 +0000 @@ -20,10 +20,17 @@ LPD8806::LPD8806(uint16_t n) { // Allocate 3 bytes per pixel: - if (NULL != (pixels = (uint8_t *)malloc(numLEDs * 3))) { +// if (NULL != (pixels = (uint8_t *)malloc(numLEDs * 3))) { memset(pixels, 0x80, numLEDs * 3); // Init to RGB 'off' state numLEDs = n; - } +// } +} + +int LPD8806::pixels_ok(void) { + if (pixels != NULL) + return 1; + else + return 0; } void LPD8806::begin(void) { @@ -61,7 +68,7 @@ // We need to have a delay here, a few ms seems to do the job // shorter may be OK as well - need to experiment :( -// wait_ms(3); + wait_ms(3); } // Convert R,G,B to combined 32-bit color @@ -76,15 +83,15 @@ void LPD8806::setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b) { if (n >= numLEDs) return; // '>=' because arrays are 0-indexed - pixels[n*3 ] = g | 0x80; - pixels[n*3+1] = r | 0x80; - pixels[n*3+2] = b | 0x80; + pixels[(n * 3) ] = g | 0x80; + pixels[(n * 3) +1 ] = r | 0x80; + pixels[(n * 3) +2 ] = b | 0x80; } void LPD8806::setPixelColor(uint16_t n, uint32_t c) { if (n >= numLEDs) return; // '>=' because arrays are 0-indexed - pixels[n*3 ] = (c >> 16) | 0x80; - pixels[n*3+1] = (c >> 8) | 0x80; - pixels[n*3+2] = c | 0x80; + pixels[(n * 3) ] = ((c >> 16) & 0xff)| 0x80; + pixels[(n * 3) + 1] = ((c >> 8) & 0xff)| 0x80; + pixels[(n * 3) + 2] = ( c & 0xff)| 0x80; }