JP Hastings-Spital
/
Knightrider_Fade
Fades the LEDs on the mbed so they look like the front of the Knightrider car :P
main.cpp@0:941cccd337df, 2010-03-14 (annotated)
- Committer:
- jphastings
- Date:
- Sun Mar 14 16:54:12 2010 +0000
- Revision:
- 0:941cccd337df
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jphastings | 0:941cccd337df | 1 | #include "mbed.h" |
jphastings | 0:941cccd337df | 2 | |
jphastings | 0:941cccd337df | 3 | PwmOut led1(LED1); |
jphastings | 0:941cccd337df | 4 | PwmOut led2(LED2); |
jphastings | 0:941cccd337df | 5 | PwmOut led3(LED3); |
jphastings | 0:941cccd337df | 6 | PwmOut led4(LED4); |
jphastings | 0:941cccd337df | 7 | |
jphastings | 0:941cccd337df | 8 | int position = 1; |
jphastings | 0:941cccd337df | 9 | int direction = 1; |
jphastings | 0:941cccd337df | 10 | int max = 50; |
jphastings | 0:941cccd337df | 11 | |
jphastings | 0:941cccd337df | 12 | int main() { |
jphastings | 0:941cccd337df | 13 | while(1) { |
jphastings | 0:941cccd337df | 14 | led1 = led1 - 0.05; |
jphastings | 0:941cccd337df | 15 | led2 = led2 - 0.05; |
jphastings | 0:941cccd337df | 16 | led3 = led3 - 0.05; |
jphastings | 0:941cccd337df | 17 | led4 = led4 - 0.05; |
jphastings | 0:941cccd337df | 18 | |
jphastings | 0:941cccd337df | 19 | if (position < (4 * max / 15)) { |
jphastings | 0:941cccd337df | 20 | } else if (position < (6 * max / 15)) { |
jphastings | 0:941cccd337df | 21 | led1 = 1; |
jphastings | 0:941cccd337df | 22 | } else if (position < (8 * max / 15)) { |
jphastings | 0:941cccd337df | 23 | led2 = 1; |
jphastings | 0:941cccd337df | 24 | } else if (position < (10 * max / 15)) { |
jphastings | 0:941cccd337df | 25 | led3 = 1; |
jphastings | 0:941cccd337df | 26 | } else if (position < (12 * max / 15)) { |
jphastings | 0:941cccd337df | 27 | led4 = 1; |
jphastings | 0:941cccd337df | 28 | } |
jphastings | 0:941cccd337df | 29 | |
jphastings | 0:941cccd337df | 30 | wait(1/max); |
jphastings | 0:941cccd337df | 31 | |
jphastings | 0:941cccd337df | 32 | if (position == max || position == 0) { |
jphastings | 0:941cccd337df | 33 | direction *= -1; |
jphastings | 0:941cccd337df | 34 | } |
jphastings | 0:941cccd337df | 35 | |
jphastings | 0:941cccd337df | 36 | position += direction; |
jphastings | 0:941cccd337df | 37 | } |
jphastings | 0:941cccd337df | 38 | } |