Demo of LED lighting effects using PWM and wait for time delays. Pins are setup for LPC1768 platform’s LEDs. For complete information, see http://developer.mbed.org/users/4180_1/notebook/led-lighting-effects-for-modelers/
Revision 0:5fc0791b9f3c, committed 2014-11-28
- Comitter:
- 4180_1
- Date:
- Fri Nov 28 18:02:35 2014 +0000
- Commit message:
- ver 1.0
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r 5fc0791b9f3c main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Nov 28 18:02:35 2014 +0000 @@ -0,0 +1,30 @@ +#include "mbed.h" +//LED welding lighting effect +PwmOut myled(LED1); +//Use PWM output to enable LED dimming + +//Use Cs random number generator rand(), but scaled and +//converted to a float 0.0 to 1.0 for PWM output +inline float random_number() +{ + return (rand()/(float(RAND_MAX))); +} + +int main() +{ + float x = 0.0; + while(1) { + //get a new random number for PWM + x = random_number(); + //add some exponential brightness scaling + //for more of a fast flash effect + myled = x*x*x; + //fast update rate for welding flashes + wait(0.02); + //add a random pause between welds + if (random_number()>0.9925) { + myled=0.0; + wait(4.0*random_number()); + } + } +} \ No newline at end of file
diff -r 000000000000 -r 5fc0791b9f3c mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Nov 28 18:02:35 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89 \ No newline at end of file