ArduinoLibs
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | List of all members
BlinkLED Class Reference

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...
 

Detailed Description

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):

#include <BlinkLED.h>
BlinkLED statusBlink(13, 70, 930);
void setup() {}
void loop() {
statusBlink.loop();
}

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.

Constructor & Destructor Documentation

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.

Member Function Documentation

bool BlinkLED::isPaused ( ) const
inline

Returns true if the LED blink cycle is paused; false otherwise.

See Also
pause(), resume()

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.

unsigned long BlinkLED::offTime ( ) const
inline

Returns the number of milliseconds the LED will be off.

See Also
onTime(), setBlinkRate()

Definition at line 36 of file BlinkLED.h.

unsigned long BlinkLED::onTime ( ) const
inline

Returns the number of milliseconds the LED will be on.

See Also
offTime(), setBlinkRate()

Definition at line 35 of file BlinkLED.h.

void BlinkLED::pause ( )
inline

Pauses the LED blink cycle in its current state().

See Also
resume(), isPaused()

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.

See Also
pause(), isPaused()

Definition at line 170 of file BlinkLED.cpp.

void BlinkLED::setBlinkRate ( unsigned long  onTime,
unsigned long  offTime 
)

Sets the onTime and offTime (in milliseconds).

The change takes effect immediately. If the current onTime() or offTime() has now expired, then the LED will immediately switch to the opposite state().

See Also
onTime(), offTime()

Definition at line 122 of file BlinkLED.cpp.

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.

See Also
state()

Definition at line 145 of file BlinkLED.cpp.

bool BlinkLED::state ( ) const
inline

Returns the current state of the LED; true is on, false is off.

See Also
setState()

Definition at line 39 of file BlinkLED.h.


The documentation for this class was generated from the following files: