My Version of The LED_WS2812 Library
Dependencies: WS2812 PixelArray
Fork of LED_WS2812 by
LED_WS2812.h@7:92f47cf3a6fd, 2018-10-23 (annotated)
- Committer:
- sepp_nepp
- Date:
- Tue Oct 23 20:17:15 2018 +0000
- Revision:
- 7:92f47cf3a6fd
- Parent:
- 5:a5e2b86a7c32
Added a few extra colors
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
garphil | 0:999518b1799b | 1 | |
garphil | 0:999518b1799b | 2 | #ifndef LED_WS2812_H |
garphil | 0:999518b1799b | 3 | #define LED_WS2812_H |
garphil | 0:999518b1799b | 4 | |
garphil | 0:999518b1799b | 5 | #include "mbed.h" |
garphil | 0:999518b1799b | 6 | #include "WS2812.h" |
garphil | 0:999518b1799b | 7 | #include "PixelArray.h" |
garphil | 0:999518b1799b | 8 | |
fbd38 | 1:64e72a25801f | 9 | /* |
garphil | 0:999518b1799b | 10 | #define ZERO_HIGH 250.0 |
garphil | 0:999518b1799b | 11 | #define ZERO_LOW 1000.0 |
garphil | 0:999518b1799b | 12 | #define ONE_HIGH 1000.0 |
garphil | 0:999518b1799b | 13 | #define ONE_LOW 250.0 |
fbd38 | 1:64e72a25801f | 14 | */ |
fbd38 | 1:64e72a25801f | 15 | #define ZERO_HIGH 200.0 |
fbd38 | 1:64e72a25801f | 16 | #define ZERO_LOW 800.0 |
fbd38 | 1:64e72a25801f | 17 | #define ONE_HIGH 800.0 |
fbd38 | 1:64e72a25801f | 18 | #define ONE_LOW 200.0 |
garphil | 0:999518b1799b | 19 | |
garphil | 0:999518b1799b | 20 | typedef enum _LED_COLORS { |
garphil | 0:999518b1799b | 21 | BLUE = 0x0000FF, |
garphil | 0:999518b1799b | 22 | LIGHTBLUE = 0x00FFF6, |
garphil | 0:999518b1799b | 23 | RED = 0xFF0000, |
alcocerg | 5:a5e2b86a7c32 | 24 | ORANGE = 0xFF3500, |
garphil | 0:999518b1799b | 25 | GREEN = 0X00FF00, |
garphil | 0:999518b1799b | 26 | BLACK = 0X000000, |
garphil | 0:999518b1799b | 27 | WHITE = 0XFFFFFF, |
garphil | 0:999518b1799b | 28 | PURPLE = 0XFF00FF, |
garphil | 0:999518b1799b | 29 | PINK = 0XFF84A3, |
garphil | 0:999518b1799b | 30 | YELLOW = 0XFFFF00, |
sepp_nepp | 7:92f47cf3a6fd | 31 | DARK_YELLOW = 0X555500, |
garphil | 0:999518b1799b | 32 | DEFAULT = 0x000000 |
garphil | 0:999518b1799b | 33 | } LED_COLORS; |
garphil | 0:999518b1799b | 34 | |
garphil | 0:999518b1799b | 35 | class LED_WS2812 |
garphil | 0:999518b1799b | 36 | { |
garphil | 0:999518b1799b | 37 | public: |
garphil | 0:999518b1799b | 38 | LED_WS2812(PinName _PinOut, int _nbLeds); |
garphil | 0:999518b1799b | 39 | ~LED_WS2812(); |
garphil | 3:ba8dc8811164 | 40 | void SetColor(LED_COLORS _color, int position); |
garphil | 3:ba8dc8811164 | 41 | void SetColor(unsigned int _color, int position); |
garphil | 0:999518b1799b | 42 | void SetColor(unsigned int _color); |
garphil | 0:999518b1799b | 43 | void SetColor(LED_COLORS _color); |
garphil | 0:999518b1799b | 44 | void ResetColor(); |
garphil | 0:999518b1799b | 45 | void SetIntensity(float perCent); |
garphil | 0:999518b1799b | 46 | |
garphil | 0:999518b1799b | 47 | void InsertColor(unsigned int _color); |
garphil | 0:999518b1799b | 48 | void InsertColor(unsigned int _color, float brightness); |
garphil | 0:999518b1799b | 49 | void InsertColorNtimes(int N, unsigned int _color, float brightness); |
garphil | 0:999518b1799b | 50 | void InsertColorNtimes(int N, unsigned int _color); |
garphil | 0:999518b1799b | 51 | |
garphil | 0:999518b1799b | 52 | void InsertColor(LED_COLORS _color); |
garphil | 0:999518b1799b | 53 | void InsertColor(LED_COLORS _color, float brightness); |
garphil | 0:999518b1799b | 54 | void InsertColorNtimes(int N, LED_COLORS _color, float brightness); |
garphil | 0:999518b1799b | 55 | void InsertColorNtimes(int N, LED_COLORS _color); |
garphil | 0:999518b1799b | 56 | |
alcocerg | 5:a5e2b86a7c32 | 57 | void StartRotation(float interval); // interval in s |
alcocerg | 5:a5e2b86a7c32 | 58 | void StopRotation(); // |
garphil | 0:999518b1799b | 59 | void Rotate(); // One Rotation |
garphil | 4:15b992a39c77 | 60 | |
alcocerg | 5:a5e2b86a7c32 | 61 | void StartBlink(float interval); // interval in s |
alcocerg | 5:a5e2b86a7c32 | 62 | void StopBlink(); // |
garphil | 4:15b992a39c77 | 63 | void Blink(); // One Rotation |
garphil | 0:999518b1799b | 64 | |
garphil | 0:999518b1799b | 65 | private: |
garphil | 0:999518b1799b | 66 | void __writeBuf(int z); |
garphil | 0:999518b1799b | 67 | void __insert2buf(); |
garphil | 0:999518b1799b | 68 | void __insertColor(unsigned int _color, int _intensity); |
garphil | 0:999518b1799b | 69 | |
garphil | 0:999518b1799b | 70 | WS2812 *ws; |
garphil | 0:999518b1799b | 71 | int nbLeds; |
garphil | 0:999518b1799b | 72 | PixelArray *pxArray; |
garphil | 0:999518b1799b | 73 | int nbInsert; |
garphil | 0:999518b1799b | 74 | PixelArray *pxInsert; |
garphil | 0:999518b1799b | 75 | Ticker LEDSystemTick; // System Callback for Rotation |
garphil | 4:15b992a39c77 | 76 | Ticker LEDBlinkSystemTick; // System Callback for Rotation |
garphil | 0:999518b1799b | 77 | bool rotationState; |
garphil | 4:15b992a39c77 | 78 | bool blinkState; |
garphil | 0:999518b1799b | 79 | int rotationPosition; |
garphil | 4:15b992a39c77 | 80 | bool blinkONOFF; // ON = true, OFF = false |
garphil | 0:999518b1799b | 81 | int intensity; |
garphil | 0:999518b1799b | 82 | }; |
garphil | 0:999518b1799b | 83 | |
garphil | 0:999518b1799b | 84 | #endif |