Optimised fork of bikeNomad's WS2811 LED control library. Supports KL25Z and KL46Z

Dependents:   CubicHand

Fork of Multi_WS2811 by Ned Konz

Optimised to use far less RAM than the original.

Capable of running up to 8 strings of 240 LEDs each with plenty of RAM to spare on the KL46Z.

Should run at least three strings of 240 LEDs on the KL25Z (RAM limited)

Committer:
Tomo2k
Date:
Wed Apr 02 11:54:27 2014 +0000
Revision:
3:2b5b03a3c0a5
Parent:
0:a8535703f23b
Child:
7:58623ad7f310
Documentation updated

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bikeNomad 0:a8535703f23b 1 // Parent class for all addressable LED strips.
bikeNomad 0:a8535703f23b 2 // Partially based on work by and (c) 2011 Jelmer Tiete
bikeNomad 0:a8535703f23b 3 // whose library is ported from the Arduino implementation of Adafruit Industries
bikeNomad 0:a8535703f23b 4 // found at: http://github.com/adafruit/LPD8806
bikeNomad 0:a8535703f23b 5 // and their strips: http://www.adafruit.com/products/306
bikeNomad 0:a8535703f23b 6 // Released under the MIT License: http://mbed.org/license/mit
bikeNomad 0:a8535703f23b 7
bikeNomad 0:a8535703f23b 8 // This is a pure virtual parent class for all LED strips, so that different types
bikeNomad 0:a8535703f23b 9 // of strip may be used in a single array or container.
bikeNomad 0:a8535703f23b 10
bikeNomad 0:a8535703f23b 11 #include "mbed.h"
bikeNomad 0:a8535703f23b 12
bikeNomad 0:a8535703f23b 13 #ifndef LEDSTRIP_H
bikeNomad 0:a8535703f23b 14 #define LEDSTRIP_H
bikeNomad 0:a8535703f23b 15
Tomo2k 3:2b5b03a3c0a5 16 /** Generic LED Strip
Tomo2k 3:2b5b03a3c0a5 17 Pure virtual parent class for all types of LED strip
Tomo2k 3:2b5b03a3c0a5 18 */
bikeNomad 0:a8535703f23b 19 class LedStrip
bikeNomad 0:a8535703f23b 20 {
bikeNomad 0:a8535703f23b 21 public:
Tomo2k 3:2b5b03a3c0a5 22 /** Create an LED strip
Tomo2k 3:2b5b03a3c0a5 23 @param n Number of RGB LEDs on the strip
Tomo2k 3:2b5b03a3c0a5 24 */
bikeNomad 0:a8535703f23b 25 LedStrip(int n);
bikeNomad 0:a8535703f23b 26 ~LedStrip();
bikeNomad 0:a8535703f23b 27
Tomo2k 3:2b5b03a3c0a5 28 //! Initialise the LED strip
bikeNomad 0:a8535703f23b 29 virtual void begin(void)=0;
Tomo2k 3:2b5b03a3c0a5 30 //! Display the LED strip
bikeNomad 0:a8535703f23b 31 virtual void show(void)=0;
Tomo2k 3:2b5b03a3c0a5 32 //! Blank the LED strip
bikeNomad 0:a8535703f23b 33 virtual void blank(void)=0;
bikeNomad 0:a8535703f23b 34
Tomo2k 3:2b5b03a3c0a5 35 /** Pack RGB Color data
Tomo2k 3:2b5b03a3c0a5 36 @param r Amount of Red
Tomo2k 3:2b5b03a3c0a5 37 @param g Amount of Green
Tomo2k 3:2b5b03a3c0a5 38 @param b Amount of Blue
Tomo2k 3:2b5b03a3c0a5 39 */
bikeNomad 0:a8535703f23b 40 static uint32_t Color(uint8_t r, uint8_t g, uint8_t b);
bikeNomad 0:a8535703f23b 41
Tomo2k 3:2b5b03a3c0a5 42 //! Number of RGB pixels
bikeNomad 0:a8535703f23b 43 uint16_t numPixels(void) { return numLEDs; }
Tomo2k 3:2b5b03a3c0a5 44 //! Number of bytes used for pixel colour data
bikeNomad 0:a8535703f23b 45 uint16_t numPixelBytes(void) { return numLEDs * 3; }
Tomo2k 3:2b5b03a3c0a5 46 //! Total brightness of all diodes\n
Tomo2k 3:2b5b03a3c0a5 47 //! Use to check power budget
bikeNomad 0:a8535703f23b 48 uint32_t total_luminance(void);
bikeNomad 0:a8535703f23b 49
Tomo2k 3:2b5b03a3c0a5 50 /** Set Blue level of pixel
Tomo2k 3:2b5b03a3c0a5 51 @param n Pixel Number
Tomo2k 3:2b5b03a3c0a5 52 @param b Amount of Blue
Tomo2k 3:2b5b03a3c0a5 53 */
bikeNomad 0:a8535703f23b 54 void setPixelB(uint16_t n, uint8_t b);
Tomo2k 3:2b5b03a3c0a5 55 /** Set Green level of pixel
Tomo2k 3:2b5b03a3c0a5 56 @param n Pixel Number
Tomo2k 3:2b5b03a3c0a5 57 @param g Amount of Green
Tomo2k 3:2b5b03a3c0a5 58 */
bikeNomad 0:a8535703f23b 59 void setPixelG(uint16_t n, uint8_t g);
Tomo2k 3:2b5b03a3c0a5 60 /** Set Red level of pixel
Tomo2k 3:2b5b03a3c0a5 61 @param n Pixel Number
Tomo2k 3:2b5b03a3c0a5 62 @param r Amount of Red
Tomo2k 3:2b5b03a3c0a5 63 */
bikeNomad 0:a8535703f23b 64 void setPixelR(uint16_t n, uint8_t r);
bikeNomad 0:a8535703f23b 65
Tomo2k 3:2b5b03a3c0a5 66 /** Set color of pixel
Tomo2k 3:2b5b03a3c0a5 67 @param n Pixel Number
Tomo2k 3:2b5b03a3c0a5 68 @param c Packed RGB color data
Tomo2k 3:2b5b03a3c0a5 69 */
bikeNomad 0:a8535703f23b 70 void setPixelColor(uint16_t n, uint32_t c);
Tomo2k 3:2b5b03a3c0a5 71 /** Set color of pixel
Tomo2k 3:2b5b03a3c0a5 72 @param n Pixel Number
Tomo2k 3:2b5b03a3c0a5 73 @param r Amount of Red
Tomo2k 3:2b5b03a3c0a5 74 @param g Amount of Green
Tomo2k 3:2b5b03a3c0a5 75 @param b Amount of Blue
Tomo2k 3:2b5b03a3c0a5 76 */
bikeNomad 0:a8535703f23b 77 void setPixelColor(uint16_t n, uint8_t r, uint8_t g, uint8_t b);
Tomo2k 3:2b5b03a3c0a5 78 /** Set color of all pixels
Tomo2k 3:2b5b03a3c0a5 79 @param *buffer Packed pixel data
Tomo2k 3:2b5b03a3c0a5 80 @param n number of pixels
Tomo2k 3:2b5b03a3c0a5 81 */
bikeNomad 0:a8535703f23b 82 void setPackedPixels(uint8_t * buffer, uint32_t n);
bikeNomad 0:a8535703f23b 83
bikeNomad 0:a8535703f23b 84 protected:
bikeNomad 0:a8535703f23b 85 uint8_t *pixels; // Holds LED color values
bikeNomad 0:a8535703f23b 86 uint16_t numLEDs; // Number of RGB LEDs in strand
bikeNomad 0:a8535703f23b 87 };
bikeNomad 0:a8535703f23b 88 #endif