ESPectro32 Library
Library for using ESPectro32 board
 All Classes Functions Variables Enumerations Enumerator Pages
ESPectro32_LED.h
1 //
2 // Created by Andri Yadi on 3/17/17.
3 //
4 
5 #ifndef ESPECTROCORE_ESPECTRO_LED_H
6 #define ESPECTROCORE_ESPECTRO_LED_H
7 
8 
9 #include <Arduino.h>
10 #include <functional>
11 
12 #include "ESPectro32_Constants.h"
13 #include <RgbLedColor.h>
14 #include <Task.h>
15 
19 enum ESPectro32_LED_AnimationType {
20  ESPectro_LED_Animation_ON,
21  ESPectro_LED_Animation_OFF,
22  ESPectro_LED_Animation_Blink,
23  ESPectro_LED_Animation_Fading,
24  ESPectro_LED_Animation_Strobo
25  };
26 
31 public:
32 
35 
36  void initPWM(byte pin, bool activeHigh = false);
37  void setAnimation(ESPectro32_LED_AnimationType animType, uint32_t speed);
38  bool runAnimation();
39 
40  void setBrightness(RgbLedColor_t maxOut)
41  {
42  this->maxOut_ = maxOut;
43  }
44 
49  void setRefreshRate(int refreshRate);
50 
51  void runAsync(void *data);
52  void start();
53  void stop();
54  void setTimeout(unsigned long timeOut) {
55  animTimeOut_ = timeOut;
56  }
57 
58  bool isAnimating() {
59  return animating_;
60  }
61 
62 private:
63 
64  ESPectro32_LED_AnimationType animationType_ = ESPectro_LED_Animation_OFF;
65  bool activeHigh_;
66  uint32_t speed_;
67  uint32_t refreshMillis_;
68  uint32_t refreshRate_; // current refresh rate
69  unsigned long animStartTime_, lastRefreshTime_;
70  unsigned long animTimeOut_ = 30000;
71  bool animating_ = false;
72 
73  byte *pins_ = NULL; // pins where the leds are attached to
74  byte numLeds_ = 1, numPins_ = 1;
75  RgbLedColor_t maxOut_;
76  RgbLedColor_t *ledColors_; // array to store leds brightness values
77  RgbLedPalette_t palette_;
78 
79  void (ESPectro32_LED_Animator::*animFunc_)();
80  void setAnimationFunc(ESPectro32_LED_AnimationType animType);
81 
82  int getStep(long t0, long t, int v);
83  float getStepFloat(long t0, long t, float v);
84 
85  void on();
86  void off();
87  void blink();
88  void fade();
89  void strobo();
90 };
91 
96 public:
97 
98  ESPectro32_LED(uint8_t pin = ESPECTRO32_LED_PIN, bool activeHigh = false);
99  ~ESPectro32_LED();
100 
104  void begin();
105  void turnOn();
106  void turnOff();
107  boolean isOn();
108  byte getPin();
109  void toggle();
110 
111  void blink(uint32_t interval = 500, uint32_t count = UINT16_MAX);
112  void fade(uint32_t duration = 2000, uint32_t count = UINT16_MAX);
113 
114  void startAnimation();
115  void stopAnimation();
116  bool isAnimating() const;
117  void setAnimation(ESPectro32_LED_AnimationType animType, uint32_t speed, uint32_t count = UINT16_MAX);
118  void setAnimationTimeout(unsigned long timeOut);
119 
120 private:
121  uint8_t pin_;
122  bool activeHigh_;
123 
124  ESPectro32_LED_Animator *animator_ = NULL;
125  ESPectro32_LED_Animator *getAnimatorPtr();
126 };
127 
128 
129 #endif //ESPECTROCORE_ESPECTRO_LED_H
The LED animator.
Definition: ESPectro32_LED.h:30
Represent LED.
Definition: ESPectro32_LED.h:95
void begin()
Must be called first before anything else.
Definition: ESPectro32_LED.cpp:41
void setRefreshRate(int refreshRate)
Definition: ESPectro32_LED.cpp:266
Definition: RgbLedColor.h:96
Definition: RgbLedColor.h:25
Encapsulate a runnable task.
Definition: Task.h:34
void runAsync(void *data)
Body of the task to execute.
Definition: ESPectro32_LED.cpp:314