FadeLed
A simple Arduino library to fade leds on hardware PWM
|
Main class of the FadeLed-library. More...
#include <FadeLed.h>
Public Member Functions | |
FadeLed (byte pin) | |
Constructor of a FadeLed object. More... | |
void | begin (byte val) |
Set a direct begin value to start at without fade. More... | |
void | set (byte val) |
Set the brightness to fade to. More... | |
byte | get () |
Returns the last set brightness. More... | |
bool | done () |
Returns if the led is done fading. More... | |
void | on () |
Fade to max brightness. More... | |
void | off () |
Fade to off. More... | |
void | beginOn () |
Sets the start brightness directly to full. More... | |
void | setTime (unsigned long time, bool constTime=false) |
Set the time a (full) fade will take. More... | |
bool | rising () |
Returns if the led is still fading up. More... | |
bool | falling () |
Returns if the led is still fading down. More... | |
Static Public Member Functions | |
static void | update () |
Updates all FadeLed objects. More... | |
static void | setInterval (unsigned int interval) |
Sets the interval at which to update the fading. More... | |
Protected Member Functions | |
void | updateThis () |
Updates fading of this object only. More... | |
Protected Attributes | |
byte | _pin |
PWM pin to control. | |
byte | _setVal |
The brightness to which last set to fade to. | |
byte | _startVal |
The brightness at which the new fade needs to start. | |
byte | _curVal |
Current brightness. | |
bool | _constTime |
Constant time fade or just constant speed fade. | |
unsigned long | _countMax |
The number of _interval's a fade should take. | |
unsigned long | _count |
The number of _interval's passed. | |
Static Protected Attributes | |
static FadeLed * | _ledList [FADE_LED_MAX_LED] |
array of pointers to all FadeLed objects | |
static byte | _ledCount = 0 |
Next number of FadeLed object. | |
static unsigned int | _interval = 50 |
Interval (in ms) between updates. | |
static unsigned int | _millisLast = 0 |
Last time all FadeLed objects where updated. | |
Main class of the FadeLed-library.
The FadeLed class includes all the functions to easily fade a led including a static function to update all constructed FadeLed objects.
FadeLed::FadeLed | ( | byte | pin | ) |
Constructor of a FadeLed object.
Makes a object to fade a specific pin. You can make a object for each PWM pin you want to fade. Updating all objects is done by simply calling update()
When created the default brightness is 0. You can start at a different brightness by calling begin().
[in] | pin | The PWM pin to fade with this object |
void FadeLed::begin | ( | byte | val | ) |
Set a direct begin value to start at without fade.
If you want to directly start the led at a certain brightness you can set it with this. This will directly set the brightness without fading.
[in] | val | The brightness to start at. |
void FadeLed::beginOn | ( | ) |
bool FadeLed::done | ( | ) |
Returns if the led is done fading.
true if the led is done fading and reached the set() value.
false if it's still fading
bool FadeLed::falling | ( | ) |
Returns if the led is still fading down.
true if fading down.
false otherwise
byte FadeLed::get | ( | ) |
void FadeLed::off | ( | ) |
void FadeLed::on | ( | ) |
Fade to max brightness.
Sets the led to fade to max brightness. Same as calling set(255)
bool FadeLed::rising | ( | ) |
Returns if the led is still fading up.
true if fading up.
false otherwise
void FadeLed::set | ( | byte | val | ) |
Set the brightness to fade to.
Set the brightness to which the led should fade to. If the led is still fading that fade is ended directly and the fade to the new value is started directly. To start fading after the current fade check if it's done via done()
In constant fade time the fade time is also reset. Even when the led was not done fading yet. So in constant fade time it will again take 'time' to reach the desired brightness.
[in] | val | The brightness to fade to. |
|
static |
Sets the interval at which to update the fading.
Only every interval when calling update() it's checked to see if the brightness of the leds needs to change (fade) to leave time for other stuff.
default: 50ms
[in] | interval | Interval in ms |
void FadeLed::setTime | ( | unsigned long | time, |
bool | constTime = false |
||
) |
Set the time a (full) fade will take.
This will set how much time a fade will take.
The real fade time will be a whole multiple of the set interval (rounded down). For example, if interval is set to 50ms and you specify a fade time of 1025ms the fading time is actually set to 1000ms.
Constant fade speed (default)
In constant fade speed this is the time a fade from off to full brightness (or vice versa) will take. A fade of less will go with the same speed but will take less time
Constant fade time
In constant fade time this is the time each fade will take. No matter how much change in brightness. Each call to set() will reset the fading time and it will fade from it's current brightness to the new brightness in this time. Useful for example if you want to fade a RGB led from one color to another in a set time. No matter the level of the individual RGB colors.
[in] | time | The time (ms) a fade will take |
[in] | constTime | [optional] true to use constant fade time. Default constant fading speed |
|
static |
Updates all FadeLed objects.
This is the core function of FadeLed. Calling this function will check each object of FadeLed to see if the brightness needs changing (fade).
It's a static function, you only need to call is once for all objects of FadeLed. You can call it using the class name like:
|
protected |