Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: Flasher_HelloWorld
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. | |
| Flasher & | operator= (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:
-
pin DigitalOut pin to connect the LED to startState State 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:
-
statein State to read back returns Time of that states flash
Definition at line 89 of file Flasher.cpp.
| int getState | ( | ) |
Read the current state of the object.
- Parameters:
-
returns The 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:
-
time Time in seconds to be in new state for newState The new state for it to be in returnState The state for it to return to
Definition at line 60 of file Flasher.cpp.
| operator int | ( | ) |
| Flasher & operator= | ( | int | statein ) |
Sets state quickly.
- Parameters:
-
statein State 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:
-
time Time 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:
-
statein State to change newTime new flash period
Definition at line 84 of file Flasher.cpp.
| void updateFlash | ( | int | statein ) |
Set new state for the obeject.
- Parameters:
-
statein New State for the object
Definition at line 39 of file Flasher.cpp.
Generated on Sat Jul 30 2022 11:57:40 by
1.7.2