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/

Dependencies:   mbed

Committer:
4180_1
Date:
Fri Nov 28 17:58:01 2014 +0000
Revision:
0:689e5e7eafb1
ver 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
4180_1 0:689e5e7eafb1 1 #include "mbed.h"
4180_1 0:689e5e7eafb1 2 //LED House Lighting effect with flickering TV and room lights randomly changing
4180_1 0:689e5e7eafb1 3 DigitalOut porch(LED1);
4180_1 0:689e5e7eafb1 4 DigitalOut room(LED2);
4180_1 0:689e5e7eafb1 5 DigitalOut room2(LED3);
4180_1 0:689e5e7eafb1 6 //DigitalOut OK for LEDs just turing on and off
4180_1 0:689e5e7eafb1 7 PwmOut TV(LED4);
4180_1 0:689e5e7eafb1 8 //Need PWM for nice flickering TV effect
4180_1 0:689e5e7eafb1 9
4180_1 0:689e5e7eafb1 10 //Use Cs random number generator rand(), but scaled and
4180_1 0:689e5e7eafb1 11 //converted to a float from 0.0 to 1.0
4180_1 0:689e5e7eafb1 12 inline float random_number()
4180_1 0:689e5e7eafb1 13 {
4180_1 0:689e5e7eafb1 14 return (rand()/(float(RAND_MAX)));
4180_1 0:689e5e7eafb1 15 }
4180_1 0:689e5e7eafb1 16
4180_1 0:689e5e7eafb1 17 int main()
4180_1 0:689e5e7eafb1 18 {
4180_1 0:689e5e7eafb1 19 float x=0.0;
4180_1 0:689e5e7eafb1 20 porch = 1;
4180_1 0:689e5e7eafb1 21 while(1) {
4180_1 0:689e5e7eafb1 22 x = random_number();
4180_1 0:689e5e7eafb1 23 TV = x;
4180_1 0:689e5e7eafb1 24 if (x >0.98) room = !room;
4180_1 0:689e5e7eafb1 25 if (x >0.99) room2 = !room2;
4180_1 0:689e5e7eafb1 26 wait(0.05);
4180_1 0:689e5e7eafb1 27 }
4180_1 0:689e5e7eafb1 28 }