WS2812B

Dependents:   high speed light Bracelet

Fork of PololuLedStrip by David Grayson

Committer:
jacob_yan
Date:
Wed Jul 23 01:29:44 2014 +0000
Revision:
22:2fcd4e3cd8ac
Parent:
19:46d7ab0ba3e7
tst r6, r6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidEGrayson 0:06475317f283 1 #include "mbed.h"
DavidEGrayson 0:06475317f283 2
DavidEGrayson 0:06475317f283 3 #ifndef _POLOLU_LED_STRIP_H
DavidEGrayson 0:06475317f283 4 #define _POLOLU_LED_STRIP_H
DavidEGrayson 0:06475317f283 5
DavidEGrayson 0:06475317f283 6 namespace Pololu
DavidEGrayson 0:06475317f283 7 {
DavidEGrayson 0:06475317f283 8 #ifndef _POLOLU_RGB_COLOR
DavidEGrayson 0:06475317f283 9 #define _POLOLU_RGB_COLOR
DavidEGrayson 1:102307d9b701 10
DavidEGrayson 1:102307d9b701 11 /** Represents an RGB color. */
DavidEGrayson 0:06475317f283 12 typedef struct rgb_color
DavidEGrayson 0:06475317f283 13 {
DavidEGrayson 1:102307d9b701 14 uint8_t red; /*!< A number between 0 and 255 that represents the brightness of the red component. */
DavidEGrayson 1:102307d9b701 15 uint8_t green; /*!< A number between 0 and 255 that represents the brightness of the green component. */
DavidEGrayson 1:102307d9b701 16 uint8_t blue; /*!< A number between 0 and 255 that represents the brightness of the blue component. */
DavidEGrayson 0:06475317f283 17 } rgb_color;
DavidEGrayson 0:06475317f283 18 #endif
DavidEGrayson 0:06475317f283 19
DavidEGrayson 0:06475317f283 20 extern "C" int led_strip_write_color(rgb_color *, volatile uint32_t * set, volatile uint32_t * clear, uint32_t mask);
DavidEGrayson 0:06475317f283 21
DavidEGrayson 18:34ba573573df 22 /** This class lets you control the addressable RGB LED strips from Pololu</a>,
DavidEGrayson 1:102307d9b701 23 or any other LED strip based on the TM1804 chip. */
DavidEGrayson 0:06475317f283 24 class PololuLedStrip
DavidEGrayson 0:06475317f283 25 {
DavidEGrayson 0:06475317f283 26 gpio_t gpio;
DavidEGrayson 1:102307d9b701 27
DavidEGrayson 0:06475317f283 28 public:
DavidEGrayson 1:102307d9b701 29
DavidEGrayson 1:102307d9b701 30 /** This constructor lets you make an led strip object by specifying the pin name.
DavidEGrayson 1:102307d9b701 31 There are no restrictions on what pin you can choose.
DavidEGrayson 1:102307d9b701 32
DavidEGrayson 1:102307d9b701 33 Example:
DavidEGrayson 1:102307d9b701 34 @code
DavidEGrayson 1:102307d9b701 35 PololuLedStrip ledStrip(p8);
DavidEGrayson 1:102307d9b701 36 @endcode
DavidEGrayson 1:102307d9b701 37 */
DavidEGrayson 0:06475317f283 38 PololuLedStrip(PinName pin);
DavidEGrayson 1:102307d9b701 39
DavidEGrayson 1:102307d9b701 40 /** Writes the specified series of colors to the LED strip.
DavidEGrayson 1:102307d9b701 41 @param colors should be a pointer to an array of rgb_color structs.
DavidEGrayson 1:102307d9b701 42 @param count should be the number of colors to write.
DavidEGrayson 1:102307d9b701 43
DavidEGrayson 1:102307d9b701 44 The first color in the array will be written to the LED closest to the data input connector.
DavidEGrayson 1:102307d9b701 45 To update all the LEDs in the LED strip, count should be equal to or greater than the number of LEDs in the strip.
DavidEGrayson 1:102307d9b701 46 If count is less than the number of LEDs in the strip, then some LEDs near the end of the strip will not be updated.
DavidEGrayson 1:102307d9b701 47
DavidEGrayson 19:46d7ab0ba3e7 48 The colors are sent in series and each color takes about 45 microseconds to send.
DavidEGrayson 1:102307d9b701 49 This function disables interrupts temporarily while it is running.
DavidEGrayson 1:102307d9b701 50 This function waits for over 10 us at the end before returning to allow the colors to take effect.
DavidEGrayson 1:102307d9b701 51 */
DavidEGrayson 0:06475317f283 52 void write(rgb_color * colors, unsigned int count);
DavidEGrayson 7:9a088f042ee0 53
DavidEGrayson 1:102307d9b701 54 /** This option defaults to <code>false</code>.
DavidEGrayson 1:102307d9b701 55 Setting this to true changes the behavior of the write function, making it enable interrupts
DavidEGrayson 1:102307d9b701 56 after each color is sent, about every 60 microseconds.
DavidEGrayson 1:102307d9b701 57 This allows your program to respond to interrupts faster, but makes it possible for an interrupt
DavidEGrayson 1:102307d9b701 58 that takes longer than 8 microseconds to screw up the transmission of colors to the LED strip.
DavidEGrayson 1:102307d9b701 59
DavidEGrayson 1:102307d9b701 60 Example:
DavidEGrayson 1:102307d9b701 61 @code
DavidEGrayson 1:102307d9b701 62 PololuLedStrip::interruptFriendly = true;
DavidEGrayson 1:102307d9b701 63 @endcode
DavidEGrayson 1:102307d9b701 64 */
DavidEGrayson 0:06475317f283 65 static bool interruptFriendly;
DavidEGrayson 7:9a088f042ee0 66
DavidEGrayson 7:9a088f042ee0 67 static void calculateDelays();
DavidEGrayson 0:06475317f283 68 };
DavidEGrayson 0:06475317f283 69 }
DavidEGrayson 0:06475317f283 70
DavidEGrayson 0:06475317f283 71 using namespace Pololu;
DavidEGrayson 0:06475317f283 72
DavidEGrayson 0:06475317f283 73 #endif