Fading LEDs timer/interrupt and PWM based.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Schueler
Date:
Mon Oct 25 16:50:33 2010 +0000
Commit message:
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Oct 25 16:50:33 2010 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+
+PwmOut led1 (LED1);
+PwmOut led2 (LED2);
+PwmOut led3 (LED3);
+PwmOut led4 (LED4);
+
+Ticker step;
+
+float delay_time = 0.001;
+float increment = 0.002;
+
+void LED_control() {
+    // ticker routine
+
+    // fading control led1
+    if ( ( led4 == 1 ) && ( led1 < 1 ) ) { led1 = led1 + increment; }
+    else if ( ( led2 == 1 ) && ( led1 > 0 ) ) { led1 = led1 - increment; }
+
+    // fading control led2
+    if ( ( led1 == 1 ) && ( led2 < 1 ) ) { led2 = led2 + increment; }
+    else if ( ( led3 == 1 ) && ( led2 > 0 ) ) { led2 = led2 - increment; }
+
+    // fading control led3
+    if ( ( led2 == 1 ) && ( led3 < 1 ) ) { led3 = led3 + increment; }
+    else if ( ( led4 == 1 ) && ( led3 > 0 ) ) { led3 = led3 - increment; }
+
+    // fading control led4
+    if ( ( led3 == 1 ) && ( led4 < 1 ) ) { led4 = led4 + increment; }
+    else if ( ( led1 == 1 ) && ( led4 > 0 ) ) { led4 = led4 - increment; }
+}
+
+
+int main() {
+    // initialize values
+    led1 = 1;
+    led2 = 0;
+    led3 = 0;
+    led4 = 0;
+
+    step.attach(&LED_control, delay_time);
+
+    while ( 1 ) // never ending story
+    {    
+        //sleep();
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Oct 25 16:50:33 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e