LedBlink library makes it possible to change blink frequency of a given LED by calling the Blink function with a float parameter elsewhere in the code to visualise state changes in a program.
LedBlink.cpp
- Committer:
- jensstruemper
- Date:
- 2015-12-07
- Revision:
- 1:e05abb2ca7dd
- Parent:
- 0:b536f9dc90ac
- Child:
- 3:9d5aa4d61bf0
File content as of revision 1:e05abb2ca7dd:
#include "mbed.h" #include "LedBlink.h" Ticker LedTicker; volatile float led_timer = 0; bool ChangeStatusFlag = false; LedBlink::LedBlink(PinName pin) :_pin(pin) { _pin = 1; } void LedBlink::LedBlinkCallback(void) { if (led_timer == 0){ _pin = 1; } if (led_timer != 0){ _pin = !_pin; if (ChangeStatusFlag) { // re-task ticker flash rate LedTicker.detach(); LedTicker.attach(this, &LedBlink::LedBlinkCallback,led_timer); ChangeStatusFlag = false; } } } void LedBlink::Blinker(float frequency){ led_timer = frequency; ChangeStatusFlag = true; LedBlinkCallback(); }