Giles Barton-Owen / Flasher

Dependents:   Flasher_HelloWorld

Embed: (wiki syntax)

« Back to documentation index

Flasher Class Reference

Flasher Class Reference

A LED Flasher class based on Ticker and Timeout. More...

#include <Flasher.h>

Public Member Functions

 Flasher (PinName pin, int startState)
 Create a Flasher object attached to the specified Pin and Start State.
void updateFlash (int statein)
 Set new state for the obeject.
int getState ()
 Read the current state of the object.
void pauseFor (float time)
 Turn the LED off for a specified period, returns to old state.
void onFor (float time, int newState, int returnState)
 Sets a new state for a while then returns to the return state.
void pause ()
 Stops the flasher until resume is called.
void resume ()
 Resumes the flasher.
void setFlashTime (int statein, float newTime)
 Configures the flash times for a specified state.
float getFlashTime (int statein)
 Reads back the flash time for a state.
Flasheroperator= (int statein)
 Sets state quickly.
 operator int ()
 Gets State quickly.

Detailed Description

A LED Flasher class based on Ticker and Timeout.

States are defined in words:

OFF, ON, SLOW, MEDIUM, QUICK or FAST

With default times of (in seconds):

Slow: 2

Medium: 1

Fast/Quick: 0.3

Example:

 // Switches LED1 through the different modes
 #include "mbed.h"
 #include "Flasher.h"
 
 Flasher myFlasher(LED1, OFF); //Defines myFlasher on LED1 starting off
 
 int main() {
      while(1){   
          wait(5);
          myFlasher = ON;
          wait(5);
          myFlasher.updateFlash(SLOW);
          wait(5);
          myFlasher = MEDIUM;
          wait(5);
          myFlasher.updateFlash(QUICK);
          wait(5);
          myFlasher.onFor(3,ON,MEDIUM);
          wait(5);
          myFlasher.pauseFor(2);
          wait(5);
          myFlasher.updateFlash(OFF);
      }
  }

Definition at line 82 of file Flasher.h.


Constructor & Destructor Documentation

Flasher ( PinName  pin,
int  startState 
)

Create a Flasher object attached to the specified Pin and Start State.

Parameters:
pinDigitalOut pin to connect the LED to
startStateState for the object to start in

Definition at line 26 of file Flasher.cpp.


Member Function Documentation

float getFlashTime ( int  statein )

Reads back the flash time for a state.

Parameters:
stateinState to read back
returnsTime of that states flash

Definition at line 89 of file Flasher.cpp.

int getState (  )

Read the current state of the object.

Parameters:
returnsThe current state

Definition at line 46 of file Flasher.cpp.

void onFor ( float  time,
int  newState,
int  returnState = 0 
)

Sets a new state for a while then returns to the return state.

Parameters:
timeTime in seconds to be in new state for
newStateThe new state for it to be in
returnStateThe state for it to return to

Definition at line 60 of file Flasher.cpp.

operator int (  )

Gets State quickly.

Parameters:
returnsCurrent state

Definition at line 147 of file Flasher.cpp.

Flasher & operator= ( int  statein )

Sets state quickly.

Parameters:
stateinState to change to

Definition at line 141 of file Flasher.cpp.

void pause (  )

Stops the flasher until resume is called.

Definition at line 70 of file Flasher.cpp.

void pauseFor ( float  time )

Turn the LED off for a specified period, returns to old state.

Parameters:
timeTime in seconds to be off for

Definition at line 51 of file Flasher.cpp.

void resume (  )

Resumes the flasher.

Definition at line 78 of file Flasher.cpp.

void setFlashTime ( int  statein,
float  newTime 
)

Configures the flash times for a specified state.

Parameters:
stateinState to change
newTimenew flash period

Definition at line 84 of file Flasher.cpp.

void updateFlash ( int  statein )

Set new state for the obeject.

Parameters:
stateinNew State for the object

Definition at line 39 of file Flasher.cpp.