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

Dependencies:   mbed

Revision:
2:67db082298a6
Parent:
1:5160ea45399b
Child:
3:20358798a986
--- a/main.cpp	Sun Sep 21 06:39:30 2014 +0000
+++ b/main.cpp	Wed May 06 13:41:36 2015 +0000
@@ -1,12 +1,26 @@
 #include "mbed.h"
 
-PwmOut led(LED1);
+PwmOut rled(LED_RED);
+PwmOut gled(LED_GREEN);
+PwmOut bled(LED_BLUE);
 
-int main() {
-    // specify period first
-    led.period(4.0f);      // 4 second period
-    led.write(0.50f);      // 50% duty cycle, relative to period
-    //led = 0.5f;          // shorthand for led.write()
-    //led.pulsewidth(2);   // alternative to led.write, set duty cycle time in seconds
-    while(1);
+int main()
+{
+    while(1) {
+        for(float p = 0.00f; p < 1.00f; p += 0.01f) {
+            rled = p;
+            wait(0.01);
+        }
+        wait (0.5);
+        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 (0.5);
+    }
 }
\ No newline at end of file