Improved visual effect. KL25Z RGB PWM LED Control, one color at a time + all colour combinations.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
lmsousa
Date:
Wed May 06 14:23:02 2015 +0000
Parent:
2:67db082298a6
Commit message:
KL25Z RGB LED controlled by PWM. Light increase and decrease on all LEDs and combinations

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 67db082298a6 -r 20358798a986 main.cpp
--- a/main.cpp	Wed May 06 13:41:36 2015 +0000
+++ b/main.cpp	Wed May 06 14:23:02 2015 +0000
@@ -1,25 +1,78 @@
 #include "mbed.h"
-
+#define pause 0.015
 PwmOut rled(LED_RED);
 PwmOut gled(LED_GREEN);
 PwmOut bled(LED_BLUE);
 
 int main()
 {
+    rled=1;
+    gled=1;
+    bled=1;
+    
     while(1) {
+        for(float p = 1.00f; p > 0.00f; p -= 0.01f) {
+            rled = p;
+            wait(pause);
+        }
         for(float p = 0.00f; p < 1.00f; p += 0.01f) {
             rled = p;
-            wait(0.01);
+            wait(pause);
+        }
+        wait (0.5);
+        for(float p = 1.00f; p > 0.00f; p -= 0.01f) {
+            gled = p;
+            wait(pause);
+        }
+        for(float p = 0.00f; p < 1.00f; p += 0.01f) {
+            gled = p;
+            wait(pause);
+        }
+        wait (0.5);
+
+        for(float p = 1.00f; p > 0.00f; p -= 0.01f) {
+            bled = p;
+            wait(pause);
+        }
+        for(float p = 0.00f; p < 1.00f; p += 0.01f) {
+            bled = p;
+            wait(pause);
         }
         wait (0.5);
+        
+        
+        for(float p = 1.00f; p > 0.00f; p -= 0.01f) {
+            rled = p;
+            gled=p;
+            wait(pause);
+        }
+        for(float p = 0.00f; p < 1.00f; p += 0.01f) {
+            rled = p;
+            gled=p;
+            wait(pause);
+        }
+        wait (0.5);
+        for(float p = 1.00f; p > 0.00f; p -= 0.01f) {
+            rled = p;
+            bled = p;
+            wait(pause);
+        }
+        for(float p = 0.00f; p < 1.00f; p += 0.01f) {
+            rled = p;
+            bled = p;
+            wait(pause);
+        }
+        wait (0.5);
+
+        for(float p = 1.00f; p > 0.00f; p -= 0.01f) {
+            gled = p;
+            bled = p;
+            wait(pause);
+        }
         for(float p = 0.00f; p < 1.00f; p += 0.01f) {
             gled = p;
-            wait(0.01);
-        }
-        wait (0.5);
-        for(float p = 0.00f; p < 1.00f; p += 0.01f) {
             bled = p;
-            wait(0.01);
+            wait(pause);
         }
         wait (0.5);
     }