![](/media/cache/profiles/ibmfp2.jpg.50x50_q85.jpg)
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:9439ccb44422, committed 2014-11-28
- Comitter:
- 4180_1
- Date:
- Fri Nov 28 18:00:06 2014 +0000
- Commit message:
- ver 1.0
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Nov 28 18:00:06 2014 +0000 @@ -0,0 +1,75 @@ +#include "mbed.h" +#include "rtos.h" +DigitalOut myled(LED1); +PwmOut myled2(LED2); +PwmOut myled3(LED3); +PwmOut myled4(LED4); + +inline float random_number(){ + return (rand()/(float(RAND_MAX))); +} + +void beacon(void const *args){ + while(1) { + //LED warm up effect using PWM + for(int i=0; i<50; i++) { + myled2 = i/50.0; + Thread::wait(1000.0*0.02); + } + //LED at full brightness level + myled2 = 1.0; + Thread::wait(1000.0*0.25); + //LED cool down effect using PWM + for(int i=49; i>0; i--) { + myled2 = i/50.0; + Thread::wait(1000.0*0.02); + } + //LED off + myled2 = 0.0; + Thread::wait(1000.0*1.5); + } +} +void welding(void const *args) { + 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 + myled3 = x*x*x; + //fast update rate for welding flashes + Thread::wait(1000.0*0.02); + //add a random pause between welds + if (random_number()>0.9925) { + myled3 = 0.0; + Thread::wait(1000.0*4.0*random_number()); + } + } +} + +void lighthouse(void const *args){ + float y=0.0; + while(1) { + for(double x=0.0; x <= 3.14159; x = x + 0.0314159) { + y = sin(x); //nice periodic function 0..1..0 + myled4 = y*y*y;//exponential effect - needs a sharp peak + Thread::wait(1000.0*.025); + } + myled4 = 0.0; + //most lighthouses have a 5 second delay - so add another 2.5 + Thread::wait(1000.0*2.5); + } +} + +int main() { + Thread thread2(beacon); + Thread thread3(welding); + Thread thread4(lighthouse); + //main runs standard LED blink demo + while(1) { + myled = 1; + Thread::wait(1000.0*0.2); + myled = 0; + Thread::wait(1000.0*0.2); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Fri Nov 28 18:00:06 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#02f5cf381388
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri Nov 28 18:00:06 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89 \ No newline at end of file