Control LED RGB with serial port to example using is send of serial port this string "255#255#255" this string is equal => Red = 255; Green = 255; Blue = 255;

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jhon309
Date:
Thu Jun 25 00:21:42 2015 +0000
Commit message:
.

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
diff -r 000000000000 -r 1f60ca10b221 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 25 00:21:42 2015 +0000
@@ -0,0 +1,36 @@
+#include "mbed.h"
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+PwmOut pwmRed(D9);//conector PWM/D9
+PwmOut pwmGreen(D10);//conector PWM/D10
+PwmOut pwmBlue(D11);//conector PWM/D11
+Serial pc(USBTX, USBRX);
+
+float const variation = 0.0039215686274509803921568627451;
+float Red = 0;
+float Green = 0;
+float Blue = 0;
+
+int main()
+{    
+    while (1) 
+    {
+        if(pc.readable()) 
+        {
+            char buffer[128];        
+            pc.gets(buffer, 20); 
+            Red = atof(strtok(buffer, "#"))* variation;
+            Green = atof(strtok(NULL, "#")) * variation;
+            Blue = atof(strtok(NULL, "#")) * variation;
+            printf("%f %f %f \n", Red, Green, Blue); 
+        }        
+        pwmRed.write(Red);     
+        pwmGreen.write(Green);  
+        pwmBlue.write(Blue);  
+        pwmRed.period_ms(1);
+        pwmGreen.period_ms(1);
+        pwmBlue.period_ms(1);  
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 1f60ca10b221 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 25 00:21:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/7cff1c4259d7
\ No newline at end of file