Let the on board RGB led run thru the color circle

Dependencies:   mbed

Test program for LPC 1549 and LPC 812 board. It use the on board RGB led to scroll thru the colors.

Files at this revision

API Documentation at this revision

Comitter:
dreschpe
Date:
Sat Oct 17 16:23:22 2015 +0000
Child:
1:c92fa914546d
Commit message:
Let the RGB led run thru the colours

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	Sat Oct 17 16:23:22 2015 +0000
@@ -0,0 +1,83 @@
+#include "mbed.h"
+
+
+/* the led's are connected to vcc, so a PwmOut of 100% will shut off the led and 0% will let it shine ! */
+PwmOut r (LED1);
+PwmOut g (LED2);
+PwmOut b (LED3);
+
+// function to convert hue , saturation and  value to RGB
+// see http://en.wikipedia.org/wiki/HSL_and_HSV
+void hsv2rgb(float H,float S, float V)
+{
+    float f,h,p,q,t;
+    int i;
+    if( S == 0.0) {
+        r = 1.0 - V;  // invert pwm !
+        g = 1.0 - V;
+        b = 1.0 - V;
+        return;
+    }
+    if(H > 360.0) H = 0.0;   // check values
+    if(S > 1.0) S = 1.0; 
+    if(S < 0.0) S = 0.0;
+    if(V > 1.0) V = 1.0;
+    if(V < 0.0) V = 0.0;
+    h = H / 60.0;
+    i = (int) h;
+    f = h - i;
+    p = V * (1.0 - S);
+    q = V * (1.0 - (S * f));
+    t = V * (1.0 - (S * (1.0 - f)));
+
+    switch(i) {
+        case 0:
+            r = 1.0 - V;  // invert pwm !
+            g = 1.0 - t;
+            b = 1.0 - p;
+            break;
+        case 1:
+            r = 1.0 - q;
+            g = 1.0 - V;
+            b = 1.0 - p;
+            break;
+        case 2:
+            r = 1.0 - p;
+            g = 1.0 - V;
+            b = 1.0 - t;
+            break;
+        case 3:
+            r = 1.0 - p;
+            g = 1.0 - q;
+            b = 1.0 - V;
+            break;
+        case 4:
+            r = 1.0 - t;
+            g = 1.0 - p;
+            b = 1.0 - V;
+            break;
+        case 5:
+        default:
+            r = 1.0 - V;
+            g = 1.0 - p;
+            b = 1.0 - q;
+            break;
+    }
+}
+
+
+
+int main() {
+    float h;       //  hue 
+    float s,v;   // saturation and  value;
+    r.period(0.001);  // set pwm period
+    s = 1.0;
+    v = 1.0;
+    h = 0.0;    
+    for(;;){   // run thru colors 
+        hsv2rgb(h,s,v);
+        wait_ms(50);
+        if(h<360) h++;
+        else h = 0;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Oct 17 16:23:22 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/34e6b704fe68
\ No newline at end of file