This application shows an example of how to control the RGB LED over RPC. The app also contains an HTTP server and uses other components such as the LCD and Temperature Sensor to display additional information.

Dependencies:   C12832_lcd EthernetInterface HTTPServer LM75B MutexLocker mbed-rpc mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
cabledev
Date:
Mon May 19 22:10:44 2014 +0000
Parent:
1:784afed9dbfe
Commit message:
- updated initial state of RGB LED;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu May 15 21:47:49 2014 +0000
+++ b/main.cpp	Mon May 19 22:10:44 2014 +0000
@@ -185,6 +185,22 @@
     }
 }
 
+void setLightProperties(float h, float s, float v, bool power)
+{
+    printf("setLightProperties: HSV = '(%2f, %2f, %2f)', Power = '%s'\n\r", h, s, v, (power ? "ON" : "OFF"));
+    
+    if (powerOn)
+    {
+        hsv2rgb(h, s, v);
+    }
+    else
+    {
+        r = 1.0;
+        g = 1.0;
+        b = 1.0;
+    }
+}
+
 void setLight(Arguments* input, Reply* output)
 {
     // Arguments are already parsed into argv array of char*
@@ -240,17 +256,7 @@
         
         printf("setLight: HSV = '(%s, %s, %s)', Brightness = '%s', Power = '%s'\n\r", strH, strS, strV, strBrightness, strPower);
         
-        // recall that the power is inverted, so (0.0 == on) and (1.0 == off)
-        if (powerOn)
-        {
-            hsv2rgb(lastH, lastS, lastV);
-        }
-        else
-        {
-            r = 1.0;
-            g = 1.0;
-            b = 1.0;
-        }
+        setLightProperties(lastH, lastS, lastV, powerOn);
     }
 }
 
@@ -333,35 +339,16 @@
 
 int main()
 {
-    // LED
-    float h; //  hue 
-    float s,v; // saturation and  value;
-    unsigned short temp;
-    
     lcd.cls();
     lcd.set_font((unsigned char*) Small_7);
     
     r.period(0.001); // set pwm period
-    s = 1.0;
     
-    // initialize the LED from the Pots
-    // get Poti 1 for color
-    temp = Pot1.read_u16();
-    temp = temp >> 6;        // truncate to 10 Bit
-    h = temp * 0.3515625;  // scale to 0 - 360;
-    //lcd.locate(0,13);
-    //lcd.printf("Colour = %3.2f degree",h);
-    // get Poti 2 fo value
-    temp = Pot2.read_u16();
-    temp = temp >> 6;
-    v = temp * 0.0009765624;  // scale to 0 - 1;
-    //lcd.locate(0,23);
-    //lcd.printf("Val = %01.3f ",v);
-    hsv2rgb(h,s,v);
-    
-    lastH = h;
-    lastS = s;
-    lastV = v;
+    // LED
+    lastH = 120;
+    lastS = 1;
+    lastV = 0.5f;
+    setLightProperties(lastH, lastS, lastV, true);
     
     //HTTPServer
     pc.baud(SERIAL_BAUD);