Simple library for controlling LEDs. Turn them on & off, blink them at specified rates and toggle their output. Don't forget to add a timer for the LEDs to use. Documentation found in header file.

Committer:
wakestrap
Date:
Thu Jul 09 13:07:50 2015 +0000
Revision:
0:8aa281e74b4a
Child:
1:1f6bd61833a3
Pre-Cleanup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wakestrap 0:8aa281e74b4a 1 #include "LEDControl.h"
wakestrap 0:8aa281e74b4a 2 #include "mbed.h"
wakestrap 0:8aa281e74b4a 3
wakestrap 0:8aa281e74b4a 4 LEDControl::LEDControl(PinName pin, Timer *time):
wakestrap 0:8aa281e74b4a 5 _led(pin),
wakestrap 0:8aa281e74b4a 6 _nextBlink( 0 ),
wakestrap 0:8aa281e74b4a 7 _Time ( time )
wakestrap 0:8aa281e74b4a 8 {
wakestrap 0:8aa281e74b4a 9 _led = 0;
wakestrap 0:8aa281e74b4a 10 }
wakestrap 0:8aa281e74b4a 11
wakestrap 0:8aa281e74b4a 12 void LEDControl::blink(float rate) {
wakestrap 0:8aa281e74b4a 13 long _currentTime = _Time->read_ms();
wakestrap 0:8aa281e74b4a 14 if(_currentTime - _nextBlink > 0)
wakestrap 0:8aa281e74b4a 15 {
wakestrap 0:8aa281e74b4a 16 if(_currentTime > 20000000)
wakestrap 0:8aa281e74b4a 17 {
wakestrap 0:8aa281e74b4a 18 _Time->reset();
wakestrap 0:8aa281e74b4a 19 _currentTime = 0;
wakestrap 0:8aa281e74b4a 20 }
wakestrap 0:8aa281e74b4a 21 _led = !_led;
wakestrap 0:8aa281e74b4a 22 _nextBlink = 1000/rate + _currentTime;
wakestrap 0:8aa281e74b4a 23 }
wakestrap 0:8aa281e74b4a 24 }
wakestrap 0:8aa281e74b4a 25 void LEDControl::off() {
wakestrap 0:8aa281e74b4a 26 _led = 0;
wakestrap 0:8aa281e74b4a 27 }
wakestrap 0:8aa281e74b4a 28
wakestrap 0:8aa281e74b4a 29 void LEDControl::on() {
wakestrap 0:8aa281e74b4a 30 _led = 1;
wakestrap 0:8aa281e74b4a 31 }
wakestrap 0:8aa281e74b4a 32
wakestrap 0:8aa281e74b4a 33 void LEDControl::toggle() {
wakestrap 0:8aa281e74b4a 34 _led = !_led;
wakestrap 0:8aa281e74b4a 35 }