![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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;
Diff: main.cpp
- Revision:
- 0:1f60ca10b221
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