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/
Diff: main.cpp
- Revision:
- 0:a903b3cf5317
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Nov 28 17:59:16 2014 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" +//LED Railroad Crossing Lighting Effect +PwmOut myled(LED1); +PwmOut myled2(LED4); +//Use a PWM output to enable dimming +//1.0 is full on, 0.0 off, 0.5 50% on + +//function to simulate incandescent bulb warm up +//and cool down cycles +void incandescent_bulb(PwmOut led, float on_time = 0.1, +float warm_time = 0.2) +{ + //LED warm up effect using PWM + for(int i=0; i<10; i++) { + led = i/10.0; + wait(warm_time/10.0); + } + //LED at full brightness level + led = 1.0; + wait(on_time); + //LED cool down effect using PWM + for(int i=9; i>0; i--) { + led = i/10.0; + wait(warm_time/10.0); + } + //LED off + led = 0.0; +} + +int main() +{ + while(1) { + incandescent_bulb(myled); + incandescent_bulb(myled2); + } +}