Thomas Milburn
/
FBRDash-tom
can't push chnages :(
Fork of FBRDash by
Diff: src/LEDS.cpp
- Revision:
- 2:825f572902c6
- Parent:
- 1:b3907b8d9f65
- Child:
- 5:177520d43c87
--- a/src/LEDS.cpp Mon Jun 25 21:01:02 2012 +0000 +++ b/src/LEDS.cpp Mon Jun 25 21:20:22 2012 +0000 @@ -1,6 +1,9 @@ #include "mbed.h" #include "LEDS.h" +//Drive the rev LEDs + +//Initialise PWM pins LEDS::LEDS(PwmOut _pins[]) { pins = _pins; @@ -8,27 +11,32 @@ pins[0].period_us(100); } +//Calculate new PWM values void LEDS::refresh(float rpm) { int value; int remainder; int i; + //Number of fully-lit LEDs value = rpm / RESOLUTION; for(i = 0; i < NUM_LEDS; i++) { if(i < value) - { + { + //First LEDs on pins[i] = 1.0; } else if(i == value) { + //Last LED partially lit - calculate intensity and set. remainder = (int)rpm % RESOLUTION; pins[i] = (float)remainder / (float)RESOLUTION; } else { + //All others off pins[i] = 0.0; } }