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.

Committer:
jensstruemper
Date:
Mon Dec 07 13:26:38 2015 +0000
Revision:
1:e05abb2ca7dd
Parent:
0:b536f9dc90ac
Child:
3:9d5aa4d61bf0
set default to LED off after object initialisation.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jensstruemper 0:b536f9dc90ac 1 #include "mbed.h"
jensstruemper 0:b536f9dc90ac 2 #include "LedBlink.h"
jensstruemper 0:b536f9dc90ac 3 Ticker LedTicker;
jensstruemper 0:b536f9dc90ac 4 volatile float led_timer = 0;
jensstruemper 0:b536f9dc90ac 5 bool ChangeStatusFlag = false;
jensstruemper 0:b536f9dc90ac 6
jensstruemper 0:b536f9dc90ac 7 LedBlink::LedBlink(PinName pin) :_pin(pin) {
jensstruemper 1:e05abb2ca7dd 8 _pin = 1;
jensstruemper 0:b536f9dc90ac 9 }
jensstruemper 0:b536f9dc90ac 10
jensstruemper 0:b536f9dc90ac 11 void LedBlink::LedBlinkCallback(void) {
jensstruemper 0:b536f9dc90ac 12 if (led_timer == 0){
jensstruemper 1:e05abb2ca7dd 13 _pin = 1;
jensstruemper 0:b536f9dc90ac 14 }
jensstruemper 0:b536f9dc90ac 15 if (led_timer != 0){
jensstruemper 0:b536f9dc90ac 16 _pin = !_pin;
jensstruemper 0:b536f9dc90ac 17 if (ChangeStatusFlag) {
jensstruemper 0:b536f9dc90ac 18 // re-task ticker flash rate
jensstruemper 0:b536f9dc90ac 19 LedTicker.detach();
jensstruemper 0:b536f9dc90ac 20 LedTicker.attach(this, &LedBlink::LedBlinkCallback,led_timer);
jensstruemper 0:b536f9dc90ac 21 ChangeStatusFlag = false;
jensstruemper 0:b536f9dc90ac 22 }
jensstruemper 0:b536f9dc90ac 23 }
jensstruemper 0:b536f9dc90ac 24 }
jensstruemper 0:b536f9dc90ac 25
jensstruemper 0:b536f9dc90ac 26 void LedBlink::Blinker(float frequency){
jensstruemper 0:b536f9dc90ac 27 led_timer = frequency;
jensstruemper 0:b536f9dc90ac 28 ChangeStatusFlag = true;
jensstruemper 0:b536f9dc90ac 29 LedBlinkCallback();
jensstruemper 0:b536f9dc90ac 30 }
jensstruemper 0:b536f9dc90ac 31