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:
0:b536f9dc90ac
Child:
1:e05abb2ca7dd

File content as of revision 0:b536f9dc90ac:

#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();
}