Dimming the leds one by one. After each led is fully lit it will go out, the next will start ligthing up.

Dependencies:   mbed

main.cpp

Committer:
LNSound
Date:
2010-10-12
Revision:
1:20d55e2596f5
Parent:
0:a5c8d616b253

File content as of revision 1:20d55e2596f5:

/*
 *  mbed demo code
 *
 *   This code has been made for a training session. 
 *
 *  Copyright (c) 2010 NXP Semiconductors Japan
 *  Released under the MIT License: http://mbed.org/license/mit
 *
 *  revision 1.0  18-Feb-2010   1st release
 */

#include "mbed.h"

PwmOut led[] = { LED4, LED3, LED2, LED1 };

int main() {

    unsigned char rate, rate2, rate3, rate4;

    rate=0;
    rate2=0;
    rate3=0;
    rate4=0;
    while ( 1 )
    {
    
       
             led[ 0 ]    = rate / 255.0;
             led[ 1 ]    = rate2 / 255.0;
             led[ 2 ]    = rate3 / 255.0;
             led[ 3 ]    = rate4 / 255.0;
    
    
               // wait( 0.01 );
                
                if (rate <255 &&  rate2 ==0 && rate3==0 && rate4==0)
                {
                rate++;
                }
                if (rate == 255)
                 rate=0;
                 
                 
                 if (rate == 0 &&  rate2 <255 && rate3==0 && rate4==0)
                {
                rate2++;
                }
                if (rate2 == 255)
                 rate2=0;
                 
                    if (rate == 0 &&  rate2 ==0 && rate3 <255 && rate4==0)
                {
                rate3++;
                }
                if (rate3 == 255)
                 rate3=0;
                 
                if (rate ==0 &&  rate2 ==0 && rate3==0 && rate4<255)
                {
                rate4++;
                }
                if (rate4 == 255)
                 rate4=0;
                
        
   
       wait( 0.01 );
    }
}