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