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.
Diff: LedBlink.cpp
- Revision:
- 0:b536f9dc90ac
- Child:
- 1:e05abb2ca7dd
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/LedBlink.cpp Mon Dec 07 12:29:33 2015 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" +#include "LedBlink.h" +Ticker LedTicker; +volatile float led_timer = 0; +bool ChangeStatusFlag = false; + +LedBlink::LedBlink(PinName pin) :_pin(pin) { + _pin = 0; + } + +void LedBlink::LedBlinkCallback(void) { + //float led1; + if (led_timer == 0){ + _pin = 0; + } + 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(); +} +