Penn Electric / ToggleFlash
Embed: (wiki syntax)

« Back to documentation index

ToggleFlash Class Reference

ToggleFlash Class Reference

LED Toggle-Flashing (50% duty) library based on Ticker interrupts instead of wait. More...

#include <ToggleFlash.h>

Public Member Functions

 ToggleFlash (PinName pin)
 Create a Flasherer object connected to a pin.
 ToggleFlash (PinName pin, float time)
 Create a Flasherer object connected to a pin and set the on-off time.
void setTime (float time)
 Set the on-off time ex.
float getTime ()
 Retrieve the current time setting of the flasher object.
void enable ()
 Enable the flasher to start toggling pin.
void disableTo (int state)
 Disable the flasher and give the pin a constant state.
int readFlasher ()
 Return the current status of the flasher.
int read ()
 Return the current state of the pin.
ToggleFlashoperator= (int state)
 An operator shorthand for disableTo(int state) to give the pin a constant state.
 operator int ()
 An operator shorthand for read() to read pin's current state.

Detailed Description

LED Toggle-Flashing (50% duty) library based on Ticker interrupts instead of wait.

Example

 Flasher myflasher(p20, 1.5);   // A flasher object attached to pin 20 with 1.5 second timing

 int main() {
     while (1) {
         myflasher.enable();          // Turn on flasher
     
         wait(3);                     // More code, simulated by wait
         myflasher.disableTo(1);      // Hold pin high
           myflasher.setTime(2);        // Set new timing
           wait(3);
           myflasher.enable();          // Resume flashing
           wait(3);
           myflasher = 0;               // Hold pin low (shorthand for disableTo(int state))
     }
 }

Definition at line 47 of file ToggleFlash.h.


Constructor & Destructor Documentation

ToggleFlash ( PinName  pin )

Create a Flasherer object connected to a pin.

Parameters:
pinThe pin to which the Flasherer is attached

Definition at line 25 of file ToggleFlash.cpp.

ToggleFlash ( PinName  pin,
float  time 
)

Create a Flasherer object connected to a pin and set the on-off time.

Parameters:
pinThe pin to which the Flasherer is attached
timeThe specified on-off time in seconds

Definition at line 28 of file ToggleFlash.cpp.


Member Function Documentation

void disableTo ( int  state )

Disable the flasher and give the pin a constant state.

Parameters:
state1 or 0 for constant on or constant off

Definition at line 48 of file ToggleFlash.cpp.

void enable (  )

Enable the flasher to start toggling pin.

Definition at line 43 of file ToggleFlash.cpp.

float getTime (  )

Retrieve the current time setting of the flasher object.

Returns:
The current on-off time of the Flasher object

Definition at line 40 of file ToggleFlash.cpp.

operator int (  )

An operator shorthand for read() to read pin's current state.

Definition at line 91 of file ToggleFlash.h.

ToggleFlash& operator= ( int  state )

An operator shorthand for disableTo(int state) to give the pin a constant state.

Definition at line 85 of file ToggleFlash.h.

int read (  )

Return the current state of the pin.

Returns:
1 or 0 for currently set high or low

Definition at line 56 of file ToggleFlash.cpp.

int readFlasher (  )

Return the current status of the flasher.

Returns:
1 or 0 for flasher enabled or flasher disabled

Definition at line 53 of file ToggleFlash.cpp.

void setTime ( float  time )

Set the on-off time ex.

1.5 means on for 1.5 seconds off for 1.5 seconds

Parameters:
timeThe specified on-off time in seconds

Definition at line 32 of file ToggleFlash.cpp.