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 
111  bool done();
112 
121  void on();
122 
131  void off();
132 
140  void beginOn();
141 
162  void setTime(unsigned long time, bool constTime = false);
163 
173  bool rising();
174 
184  bool falling();
185 
186 
203  static void update();
204 
218  static void setInterval(unsigned int interval);
219 
220 
221  protected:
222  byte _pin;
223  byte _setVal;
224  byte _startVal;
225  byte _curVal;
226  bool _constTime;
227  unsigned long _countMax;
228  unsigned long _count;
229 
230 
239  void updateThis();
240 
242  static byte _ledCount;
243  static unsigned int _interval;
244  static unsigned int _millisLast;
245 };
246 
247 
248 #endif
bool falling()
Returns if the led is still fading down.
Definition: FadeLed.cpp:67
void updateThis()
Updates fading of this object only.
Definition: FadeLed.cpp:71
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:45
byte _startVal
The brightness at which the new fade needs to start.
Definition: FadeLed.h:224
unsigned long _count
The number of _interval's passed.
Definition: FadeLed.h:228
static void setInterval(unsigned int interval)
Sets the interval at which to update the fading.
Definition: FadeLed.cpp:141
byte _setVal
The brightness to which last set to fade to.
Definition: FadeLed.h:223
#define FADE_LED_MAX_LED
Maximum number of FadeLed objects.
Definition: FadeLed.h:23
void off()
Fade to off.
Definition: FadeLed.cpp:49
void setTime(unsigned long time, bool constTime=false)
Set the time a (full) fade will take.
Definition: FadeLed.cpp:57
static unsigned int _interval
Interval (in ms) between updates.
Definition: FadeLed.h:243
static FadeLed * _ledList[FADE_LED_MAX_LED]
array of pointers to all FadeLed objects
Definition: FadeLed.h:241
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:244
byte _pin
PWM pin to control.
Definition: FadeLed.h:222
bool _constTime
Constant time fade or just constant speed fade.
Definition: FadeLed.h:226
unsigned long _countMax
The number of _interval's a fade should take.
Definition: FadeLed.h:227
static byte _ledCount
Next number of FadeLed object.
Definition: FadeLed.h:242
bool done()
Returns if the led is done fading.
Definition: FadeLed.cpp:41
bool rising()
Returns if the led is still fading up.
Definition: FadeLed.cpp:63
static void update()
Updates all FadeLed objects.
Definition: FadeLed.cpp:145
void beginOn()
Sets the start brightness directly to full.
Definition: FadeLed.cpp:53
byte _curVal
Current brightness.
Definition: FadeLed.h:225