ArduinoLibs
|
Chase LED's on output pins in a defined sequence. More...
#include <ChaseLEDs.h>
Public Member Functions | |
ChaseLEDs (const uint8_t *pins, int num, unsigned long advanceTime) | |
Initializes the LED chaser. More... | |
void | loop () |
unsigned long | advanceTime () const |
Returns the number of milliseconds that each LED will be lit in the chase sequence. More... | |
void | setAdvanceTime (unsigned long advanceTime) |
Sets the number of milliseconds to advance between LED's to advanceTime. More... | |
Protected Member Functions | |
virtual void | advance (uint8_t prevPin, uint8_t nextPin) |
Advances to the next LED in sequence, turning off prevPin, and turning on nextPin. More... | |
uint8_t | previousPin (int n) const |
Returns the pin that is n steps back in the sequence. More... | |
Chase LED's on output pins in a defined sequence.
The following example performs a LED chase over the 6 PWM outputs on the Arduino Uno, with a 150 millisecond delay between each LED:
After pin 11 is lit, the pattern will repeat at pin 3. To cause the chase to oscillate back and forth instead, extend the sequence as follows:
See the Cylon example for more information on how to use the ChaseLEDs class in a practical application.
Definition at line 28 of file ChaseLEDs.h.
ChaseLEDs::ChaseLEDs | ( | const uint8_t * | pins, |
int | num, | ||
unsigned long | advanceTime | ||
) |
Initializes the LED chaser.
The chase sequence consists of num pins, whose names are given by the pins array. Each LED is lit for advanceTime milliseconds before advancing to the next LED.
This constructor configures all of the pins for output and sets their state to be LOW. The first LED will be lit when the program first calls loop().
Definition at line 71 of file ChaseLEDs.cpp.
|
protectedvirtual |
Advances to the next LED in sequence, turning off prevPin, and turning on nextPin.
The default implementation is equivalent to the following code:
This method may be overridden in subclasses to provide special effects. See the documentation for previousPin() for some example effects.
Definition at line 136 of file ChaseLEDs.cpp.
|
inline |
Returns the number of milliseconds that each LED will be lit in the chase sequence.
Definition at line 35 of file ChaseLEDs.h.
void ChaseLEDs::loop | ( | ) |
Perform a single iteration of the control loop for this LED chaser.
Definition at line 87 of file ChaseLEDs.cpp.
|
inlineprotected |
Returns the pin that is n steps back in the sequence.
If n is zero, then the current pin is returned; if n is 1, then the previous pin is returned; and so on.
This function may be called by subclasses in their advance() method to manipulate pins that are further back in the chase sequence than the immediately previous pin.
For example, the following code implements a LED chaser that lights two pins at a time:
As another exmaple, the following code uses PWM outputs to fade out the previous pin rather than turn it off immediately:
Note: it is possible to retrieve the following pin in sequence using previousPin(-1). This could be used to fade in the LED that follows nextPin.
Definition at line 40 of file ChaseLEDs.h.
|
inline |
Sets the number of milliseconds to advance between LED's to advanceTime.
Definition at line 36 of file ChaseLEDs.h.