First Simon Says version

Dependencies:   mbed DebounceIn WS2812

Committer:
elab
Date:
Thu Feb 13 09:07:14 2020 +0000
Revision:
0:47b1ab4dd893
first version

Who changed what in which revision?

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