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@0:b536f9dc90ac, 2015-12-07 (annotated)
- Committer:
- jensstruemper
- Date:
- Mon Dec 07 12:29:33 2015 +0000
- Revision:
- 0:b536f9dc90ac
- Child:
- 1:e05abb2ca7dd
LedBlink initial commit.
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:b536f9dc90ac | 8 | _pin = 0; |
jensstruemper | 0:b536f9dc90ac | 9 | } |
jensstruemper | 0:b536f9dc90ac | 10 | |
jensstruemper | 0:b536f9dc90ac | 11 | void LedBlink::LedBlinkCallback(void) { |
jensstruemper | 0:b536f9dc90ac | 12 | //float led1; |
jensstruemper | 0:b536f9dc90ac | 13 | if (led_timer == 0){ |
jensstruemper | 0:b536f9dc90ac | 14 | _pin = 0; |
jensstruemper | 0:b536f9dc90ac | 15 | } |
jensstruemper | 0:b536f9dc90ac | 16 | if (led_timer != 0){ |
jensstruemper | 0:b536f9dc90ac | 17 | _pin = !_pin; |
jensstruemper | 0:b536f9dc90ac | 18 | if (ChangeStatusFlag) { |
jensstruemper | 0:b536f9dc90ac | 19 | // re-task ticker flash rate |
jensstruemper | 0:b536f9dc90ac | 20 | LedTicker.detach(); |
jensstruemper | 0:b536f9dc90ac | 21 | LedTicker.attach(this, &LedBlink::LedBlinkCallback,led_timer); |
jensstruemper | 0:b536f9dc90ac | 22 | ChangeStatusFlag = false; |
jensstruemper | 0:b536f9dc90ac | 23 | } |
jensstruemper | 0:b536f9dc90ac | 24 | } |
jensstruemper | 0:b536f9dc90ac | 25 | } |
jensstruemper | 0:b536f9dc90ac | 26 | |
jensstruemper | 0:b536f9dc90ac | 27 | void LedBlink::Blinker(float frequency){ |
jensstruemper | 0:b536f9dc90ac | 28 | led_timer = frequency; |
jensstruemper | 0:b536f9dc90ac | 29 | ChangeStatusFlag = true; |
jensstruemper | 0:b536f9dc90ac | 30 | LedBlinkCallback(); |
jensstruemper | 0:b536f9dc90ac | 31 | } |
jensstruemper | 0:b536f9dc90ac | 32 |