Detected people approaching if the distance is < 6 feet then LEDs blinking RED otherwise LEDs light green.

Dependencies:   mbed X_NUCLEO_53L1A1_mbed WS2812

Committer:
elab
Date:
Tue Sep 29 09:30:43 2020 +0000
Revision:
0:ea8694e55809
first version

Who changed what in which revision?

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