ArduinoLibs
|
Blink a LED on a digital output pin. More...
#include <BlinkLED.h>
Public Member Functions | |
BlinkLED (uint8_t pin, unsigned long onTime, unsigned long offTime, bool initialState=false) | |
Initialize a blinking LED on the specified pin. More... | |
void | loop () |
unsigned long | onTime () const |
Returns the number of milliseconds the LED will be on. More... | |
unsigned long | offTime () const |
Returns the number of milliseconds the LED will be off. More... | |
void | setBlinkRate (unsigned long onTime, unsigned long offTime) |
Sets the onTime and offTime (in milliseconds). More... | |
bool | state () const |
Returns the current state of the LED; true is on, false is off. More... | |
void | setState (bool state) |
Sets the current state of the LED, where true is on, false is off. More... | |
void | pause () |
Pauses the LED blink cycle in its current state(). More... | |
void | resume () |
Resumes the LED blink cycle after a pause(). More... | |
bool | isPaused () const |
Returns true if the LED blink cycle is paused; false otherwise. More... | |
Blink a LED on a digital output pin.
BlinkLED simplies the process of blinking a LED by encapsulating the control logic into a single class. The following example strobes the status LED on D13 with a period of 70 milliseconds on, 930 milliseconds off (the LED is initially off):
The current state() of the LED can be changed immediately by calling setState(). The blink rate can be modified with setBlinkRate(). And the blink cycle can be suspended and restarted with pause() and resume().
Definition at line 28 of file BlinkLED.h.
BlinkLED::BlinkLED | ( | uint8_t | pin, |
unsigned long | onTime, | ||
unsigned long | offTime, | ||
bool | initialState = false |
||
) |
Initialize a blinking LED on the specified pin.
The LED will blink with a rate defined by onTime and offTime (in milliseconds). Initially the LED's state is given by initialState, where true means initially on and false means initially off.
Definition at line 64 of file BlinkLED.cpp.
|
inline |
Returns true if the LED blink cycle is paused; false otherwise.
Definition at line 44 of file BlinkLED.h.
void BlinkLED::loop | ( | ) |
Perform a single iteration of the blink loop for this LED.
Definition at line 79 of file BlinkLED.cpp.
|
inline |
Returns the number of milliseconds the LED will be off.
Definition at line 36 of file BlinkLED.h.
|
inline |
Returns the number of milliseconds the LED will be on.
Definition at line 35 of file BlinkLED.h.
|
inline |
Pauses the LED blink cycle in its current state().
Definition at line 42 of file BlinkLED.h.
void BlinkLED::resume | ( | ) |
Resumes the LED blink cycle after a pause().
The LED will complete its current onTime() or offTime() and then will switch to the opposite state(). If onTime() or offTime() has already expired, then the LED will immediately switch state.
Definition at line 170 of file BlinkLED.cpp.
void BlinkLED::setBlinkRate | ( | unsigned long | onTime, |
unsigned long | offTime | ||
) |
void BlinkLED::setState | ( | bool | state | ) |
Sets the current state of the LED, where true is on, false is off.
If the LED is already set to state, then it will complete its current cycle of onTime() or offTime(). Otherwise the LED is immediately set to state and a new cycle begins.
Definition at line 145 of file BlinkLED.cpp.
|
inline |
Returns the current state of the LED; true is on, false is off.
Definition at line 39 of file BlinkLED.h.