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

Dependencies:   mbed

Committer:
LNSound
Date:
Tue Oct 12 19:24:07 2010 +0000
Revision:
0:a5c8d616b253
Child:
1:20d55e2596f5

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
LNSound 0:a5c8d616b253 1 /*
LNSound 0:a5c8d616b253 2 * mbed demo code
LNSound 0:a5c8d616b253 3 *
LNSound 0:a5c8d616b253 4 * This code has been made for a training session.
LNSound 0:a5c8d616b253 5 *
LNSound 0:a5c8d616b253 6 * Copyright (c) 2010 NXP Semiconductors Japan
LNSound 0:a5c8d616b253 7 * Released under the MIT License: http://mbed.org/license/mit
LNSound 0:a5c8d616b253 8 *
LNSound 0:a5c8d616b253 9 * revision 1.0 18-Feb-2010 1st release
LNSound 0:a5c8d616b253 10 */
LNSound 0:a5c8d616b253 11
LNSound 0:a5c8d616b253 12 #include "mbed.h"
LNSound 0:a5c8d616b253 13
LNSound 0:a5c8d616b253 14 PwmOut led[] = { LED4, LED3, LED2, LED1 };
LNSound 0:a5c8d616b253 15
LNSound 0:a5c8d616b253 16 int main() {
LNSound 0:a5c8d616b253 17
LNSound 0:a5c8d616b253 18 unsigned char rate, rate2, rate3, rate4;
LNSound 0:a5c8d616b253 19
LNSound 0:a5c8d616b253 20 rate=0;
LNSound 0:a5c8d616b253 21 rate2=0;
LNSound 0:a5c8d616b253 22 rate3=0;
LNSound 0:a5c8d616b253 23 rate4=0;
LNSound 0:a5c8d616b253 24 while ( 1 )
LNSound 0:a5c8d616b253 25 {
LNSound 0:a5c8d616b253 26
LNSound 0:a5c8d616b253 27
LNSound 0:a5c8d616b253 28 led[ 0 ] = rate / 255.0;
LNSound 0:a5c8d616b253 29 led[ 1 ] = rate2 / 255.0;
LNSound 0:a5c8d616b253 30 led[ 2 ] = rate3 / 255.0;
LNSound 0:a5c8d616b253 31 led[ 3 ] = rate4 / 255.0;
LNSound 0:a5c8d616b253 32
LNSound 0:a5c8d616b253 33
LNSound 0:a5c8d616b253 34 // wait( 0.01 );
LNSound 0:a5c8d616b253 35
LNSound 0:a5c8d616b253 36 if (rate <255 && rate2 ==0 && rate3==0 && rate4==0)
LNSound 0:a5c8d616b253 37 {
LNSound 0:a5c8d616b253 38 rate++;
LNSound 0:a5c8d616b253 39 }
LNSound 0:a5c8d616b253 40 if (rate == 255)
LNSound 0:a5c8d616b253 41 rate=0;
LNSound 0:a5c8d616b253 42
LNSound 0:a5c8d616b253 43
LNSound 0:a5c8d616b253 44 if (rate == 0 && rate2 <255 && rate3==0 && rate4==0)
LNSound 0:a5c8d616b253 45 {
LNSound 0:a5c8d616b253 46 rate2++;
LNSound 0:a5c8d616b253 47 }
LNSound 0:a5c8d616b253 48 if (rate2 == 255)
LNSound 0:a5c8d616b253 49 rate2=0;
LNSound 0:a5c8d616b253 50
LNSound 0:a5c8d616b253 51 if (rate == 0 && rate2 ==0 && rate3 <255 && rate4==0)
LNSound 0:a5c8d616b253 52 {
LNSound 0:a5c8d616b253 53 rate3++;
LNSound 0:a5c8d616b253 54 }
LNSound 0:a5c8d616b253 55 if (rate3 == 255)
LNSound 0:a5c8d616b253 56 rate3=0;
LNSound 0:a5c8d616b253 57
LNSound 0:a5c8d616b253 58 if (rate ==0 && rate2 ==0 && rate3==0 && rate4<255)
LNSound 0:a5c8d616b253 59 {
LNSound 0:a5c8d616b253 60 rate4++;
LNSound 0:a5c8d616b253 61 }
LNSound 0:a5c8d616b253 62 if (rate4 == 255)
LNSound 0:a5c8d616b253 63 rate4=0;
LNSound 0:a5c8d616b253 64
LNSound 0:a5c8d616b253 65
LNSound 0:a5c8d616b253 66
LNSound 0:a5c8d616b253 67 /* for (unsigned char rate3=0; rate<=255; rate3++)
LNSound 0:a5c8d616b253 68 {
LNSound 0:a5c8d616b253 69 led[ 1 ] = rate3 / 255.0;
LNSound 0:a5c8d616b253 70 // wait( 0.01 );
LNSound 0:a5c8d616b253 71 }
LNSound 0:a5c8d616b253 72
LNSound 0:a5c8d616b253 73 for (unsigned char rate4=0; rate<=255; rate4++)
LNSound 0:a5c8d616b253 74 {
LNSound 0:a5c8d616b253 75 led[ 3 ] = rate4 / 255.0;
LNSound 0:a5c8d616b253 76 // wait( 0.01 );
LNSound 0:a5c8d616b253 77 }
LNSound 0:a5c8d616b253 78
LNSound 0:a5c8d616b253 79
LNSound 0:a5c8d616b253 80 // led[ 2 ] = rate / 255.0;
LNSound 0:a5c8d616b253 81 //// led[ 1 ] = 1- (rate / 255.0);
LNSound 0:a5c8d616b253 82 // led[ 3 ] = 1- (rate / 255.0);
LNSound 0:a5c8d616b253 83 // rate++;
LNSound 0:a5c8d616b253 84
LNSound 0:a5c8d616b253 85 */ wait( 0.01 );
LNSound 0:a5c8d616b253 86 }
LNSound 0:a5c8d616b253 87 }
LNSound 0:a5c8d616b253 88
LNSound 0:a5c8d616b253 89 #if 0
LNSound 0:a5c8d616b253 90 // for ( int i = 0, r = rate; i < 4; i++, r += 32 )
LNSound 0:a5c8d616b253 91 // led[ i ] = ((r & 0x80) ? (unsigned char)(~r) : (unsigned char)r) / 255.0;
LNSound 0:a5c8d616b253 92
LNSound 0:a5c8d616b253 93 rate += 4;
LNSound 0:a5c8d616b253 94
LNSound 0:a5c8d616b253 95 wait( 0.01 );
LNSound 0:a5c8d616b253 96 #endif
LNSound 0:a5c8d616b253 97 /*
LNSound 0:a5c8d616b253 98 #if 0
LNSound 0:a5c8d616b253 99 led[ 0 ] = (unsigned char)rate / 255.0;
LNSound 0:a5c8d616b253 100 led[ 2 ] = (unsigned char)rate / 255.0;
LNSound 0:a5c8d616b253 101 led[ 1 ] = 1- ((unsigned char)rate / 255.0);
LNSound 0:a5c8d616b253 102 led[ 3 ] = 1- ((unsigned char)rate / 255.0);
LNSound 0:a5c8d616b253 103 rate++;
LNSound 0:a5c8d616b253 104
LNSound 0:a5c8d616b253 105 wait( 0.01 );
LNSound 0:a5c8d616b253 106 #endif
LNSound 0:a5c8d616b253 107 */