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/
main.cpp@0:4420127af442, 2014-11-28 (annotated)
- Committer:
- 4180_1
- Date:
- Fri Nov 28 18:01:14 2014 +0000
- Revision:
- 0:4420127af442
ver 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
4180_1 | 0:4420127af442 | 1 | #include "mbed.h" |
4180_1 | 0:4420127af442 | 2 | //LED Lighthouse or Searchlight lighting effect |
4180_1 | 0:4420127af442 | 3 | PwmOut myled(LED1); |
4180_1 | 0:4420127af442 | 4 | //use Pwm output for dimming |
4180_1 | 0:4420127af442 | 5 | |
4180_1 | 0:4420127af442 | 6 | int main() |
4180_1 | 0:4420127af442 | 7 | { |
4180_1 | 0:4420127af442 | 8 | float y=0.0; |
4180_1 | 0:4420127af442 | 9 | while(1) { |
4180_1 | 0:4420127af442 | 10 | for(double x=0.0; x <= 3.14159; x = x + 0.0314159) { |
4180_1 | 0:4420127af442 | 11 | y = sin(x); //nice periodic function 0..1..0 |
4180_1 | 0:4420127af442 | 12 | myled = y*y*y;//exponential effect - needs a sharp peak |
4180_1 | 0:4420127af442 | 13 | wait(.025); |
4180_1 | 0:4420127af442 | 14 | } |
4180_1 | 0:4420127af442 | 15 | myled = 0.0; |
4180_1 | 0:4420127af442 | 16 | //most lighthouses have a 5 second delay - so add another 2.5 |
4180_1 | 0:4420127af442 | 17 | wait(2.5); |
4180_1 | 0:4420127af442 | 18 | } |
4180_1 | 0:4420127af442 | 19 | } |