Fades the LEDs on the mbed so they look like the front of the Knightrider car :P

Dependencies:   mbed

main.cpp

Committer:
jphastings
Date:
2010-03-14
Revision:
0:941cccd337df

File content as of revision 0:941cccd337df:

#include "mbed.h"

PwmOut led1(LED1);
PwmOut led2(LED2);
PwmOut led3(LED3);
PwmOut led4(LED4);

int position = 1;
int direction = 1;
int max = 50;

int main() {  
    while(1) {
        led1 = led1 - 0.05;
        led2 = led2 - 0.05;
        led3 = led3 - 0.05;
        led4 = led4 - 0.05;
    
        if (position < (4 * max / 15)) {
        } else if (position < (6 * max / 15)) {
            led1 = 1;
        } else if (position < (8 * max / 15)) {
            led2 = 1;
        } else if (position < (10 * max / 15)) {
            led3 = 1;
        } else if (position < (12 * max / 15)) {
            led4 = 1;
        }
        
        wait(1/max);
        
        if (position == max || position == 0) {
            direction *= -1;
        }
        
        position += direction;
    }
}