RGB Spectrum Fader. A nice RGB color spectrum cycling Demo

Dependencies:   mbed

Fork of frdm_rgbled by Freescale

Files at this revision

API Documentation at this revision

Comitter:
lasmahei
Date:
Wed Nov 19 14:34:11 2014 +0000
Parent:
8:a6c27db26c21
Commit message:
Added Bit resolution setting and improved overall brightness

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
--- a/main.cpp	Fri May 30 14:34:49 2014 +0000
+++ b/main.cpp	Wed Nov 19 14:34:11 2014 +0000
@@ -5,31 +5,31 @@
 PwmOut b(LED_BLUE);
 
     float color,red,green,blue;
-    float colorRange = 1024;
-    short unsigned i;
+    unsigned int colorRes = 10; // Bit
+    float colorRange = 1;
+    unsigned int colorInt;
+    unsigned int i;
 
 int main() 
 {
-
-    r.period(0.01);
-    g.period(0.01);
-    b.period(0.01);
+    for(i=1; i<=colorRes; i++) colorRange = colorRange*2;
+    
+    r.period_ms(10);
+    g.period_ms(10);
+    b.period_ms(10);
 
     while (true) 
     {
-        for (i=0; i<=colorRange; i++)
-        {    
-            color = (1/colorRange)*i;
-             
-            if(color >= 0 && color <= 0.3333 ) { red = 0.3333-color; green = color; blue = 0; }
-            if(color > 0.3333 && color <= 0.6666) { red = 0; green =0.6666-color; blue = color-0.3333; }
-            if(color > 0.6666 && color <= 1) { red = color-0.6666; green = 0; blue = 1-color; }
-            
+        for (colorInt=0; colorInt <= colorRange; colorInt++)
+        {                 
+            color = (1/colorRange)*colorInt;
+            if(colorInt >= 0 && colorInt <= colorRange/3 ) { red = 1-(color*3); green = color*3; blue = 0; }
+            if(colorInt > colorRange/3 && colorInt <= 2*colorRange/3) { red = 0; green = 2-(color*3); blue = (color*3)-1; }
+            if(colorInt > 2*colorRange/3 && colorInt <= colorRange) { red = (color*3)-2; green = 0; blue = (1-color)*3; }
             r=1-red;
             g=1-green;
             b=1-blue;
-
-            wait(0.1);
+            wait_ms(100);
         }
     }
 }
\ No newline at end of file
--- a/mbed.bld	Fri May 30 14:34:49 2014 +0000
+++ b/mbed.bld	Wed Nov 19 14:34:11 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/031413cf7a89
\ No newline at end of file