Nando Daenen
/
DimmingLeds
Dimming the leds one by one. After each led is fully lit it will go out, the next will start ligthing up.
Diff: main.cpp
- Revision:
- 0:a5c8d616b253
- Child:
- 1:20d55e2596f5
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 12 19:24:07 2010 +0000 @@ -0,0 +1,107 @@ +/* + * 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; + + + + /* for (unsigned char rate3=0; rate<=255; rate3++) + { + led[ 1 ] = rate3 / 255.0; + // wait( 0.01 ); + } + + for (unsigned char rate4=0; rate<=255; rate4++) + { + led[ 3 ] = rate4 / 255.0; + // wait( 0.01 ); + } + + + // led[ 2 ] = rate / 255.0; + //// led[ 1 ] = 1- (rate / 255.0); + // led[ 3 ] = 1- (rate / 255.0); + // rate++; + + */ wait( 0.01 ); + } +} + +#if 0 + // for ( int i = 0, r = rate; i < 4; i++, r += 32 ) + // led[ i ] = ((r & 0x80) ? (unsigned char)(~r) : (unsigned char)r) / 255.0; + + rate += 4; + + wait( 0.01 ); +#endif +/* +#if 0 + led[ 0 ] = (unsigned char)rate / 255.0; + led[ 2 ] = (unsigned char)rate / 255.0; + led[ 1 ] = 1- ((unsigned char)rate / 255.0); + led[ 3 ] = 1- ((unsigned char)rate / 255.0); + rate++; + + wait( 0.01 ); +#endif +*/