FadeLed
A simple Arduino library to fade leds on hardware PWM
FadeLed.h
Go to the documentation of this file.
1 
8 #ifndef _FADE_LED_H
9 #define _FADE_LED_H
10 
11 #if defined(ARDUINO) && ARDUINO >= 100
12 #include "Arduino.h"
13 #else
14 #include "WProgram.h"
15 #endif
16 
22 #ifndef FADE_LED_MAX_LED
23 #define FADE_LED_MAX_LED 6
24 #endif
25 
33 #ifndef FADE_LED_RESOLUTION
34 #define FADE_LED_RESOLUTION 255
35 #endif
36 
44 class FadeLed{
45  public:
61  FadeLed(byte pin);
62 
74  void begin(byte val);
75 
89  void set(byte val);
90 
100  byte get();
101 
113  byte getCurrent();
114 
124  bool done();
125 
134  void on();
135 
144  void off();
145 
153  void beginOn();
154 
175  void setTime(unsigned long time, bool constTime = false);
176 
186  bool rising();
187 
197  bool falling();
198 
206  void stop();
207 
208 
225  static void update();
226 
240  static void setInterval(unsigned int interval);
241 
242 
243  protected:
244  byte _pin;
245  byte _setVal;
246  byte _startVal;
247  byte _curVal;
248  bool _constTime;
249  unsigned long _countMax;
250  unsigned long _count;
251 
252 
261  void updateThis();
262 
264  static byte _ledCount;
265  static unsigned int _interval;
266  static unsigned int _millisLast;
267 };
268 
269 
270 #endif
bool falling()
Returns if the led is still fading down.
Definition: FadeLed.cpp:74
void updateThis()
Updates fading of this object only.
Definition: FadeLed.cpp:82
Main class of the FadeLed-library.
Definition: FadeLed.h:44
FadeLed(byte pin)
Constructor of a FadeLed object.
Definition: FadeLed.cpp:9
void on()
Fade to max brightness.
Definition: FadeLed.cpp:52
byte _startVal
The brightness at which the new fade needs to start.
Definition: FadeLed.h:246
unsigned long _count
The number of _interval's passed.
Definition: FadeLed.h:250
static void setInterval(unsigned int interval)
Sets the interval at which to update the fading.
Definition: FadeLed.cpp:152
byte _setVal
The brightness to which last set to fade to.
Definition: FadeLed.h:245
#define FADE_LED_MAX_LED
Maximum number of FadeLed objects.
Definition: FadeLed.h:23
void off()
Fade to off.
Definition: FadeLed.cpp:56
void setTime(unsigned long time, bool constTime=false)
Set the time a (full) fade will take.
Definition: FadeLed.cpp:64
static unsigned int _interval
Interval (in ms) between updates.
Definition: FadeLed.h:265
static FadeLed * _ledList[FADE_LED_MAX_LED]
array of pointers to all FadeLed objects
Definition: FadeLed.h:263
void begin(byte val)
Set a direct begin value to start at without fade.
Definition: FadeLed.cpp:20
static unsigned int _millisLast
Last time all FadeLed objects where updated.
Definition: FadeLed.h:266
byte _pin
PWM pin to control.
Definition: FadeLed.h:244
bool _constTime
Constant time fade or just constant speed fade.
Definition: FadeLed.h:248
unsigned long _countMax
The number of _interval's a fade should take.
Definition: FadeLed.h:249
static byte _ledCount
Next number of FadeLed object.
Definition: FadeLed.h:264
bool done()
Returns if the led is done fading.
Definition: FadeLed.cpp:48
bool rising()
Returns if the led is still fading up.
Definition: FadeLed.cpp:70
void stop()
Stops the current fading.
Definition: FadeLed.cpp:78
static void update()
Updates all FadeLed objects.
Definition: FadeLed.cpp:156
void beginOn()
Sets the start brightness directly to full.
Definition: FadeLed.cpp:60
byte _curVal
Current brightness.
Definition: FadeLed.h:247
byte getCurrent()
Returns the current brightness.
Definition: FadeLed.cpp:44