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

Committer:
jhon309
Date:
Thu Jun 25 00:21:42 2015 +0000
Revision:
0:1f60ca10b221
.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhon309 0:1f60ca10b221 1 #include "mbed.h"
jhon309 0:1f60ca10b221 2 #include <string.h>
jhon309 0:1f60ca10b221 3 #include <stdlib.h>
jhon309 0:1f60ca10b221 4 #include <stdio.h>
jhon309 0:1f60ca10b221 5
jhon309 0:1f60ca10b221 6 PwmOut pwmRed(D9);//conector PWM/D9
jhon309 0:1f60ca10b221 7 PwmOut pwmGreen(D10);//conector PWM/D10
jhon309 0:1f60ca10b221 8 PwmOut pwmBlue(D11);//conector PWM/D11
jhon309 0:1f60ca10b221 9 Serial pc(USBTX, USBRX);
jhon309 0:1f60ca10b221 10
jhon309 0:1f60ca10b221 11 float const variation = 0.0039215686274509803921568627451;
jhon309 0:1f60ca10b221 12 float Red = 0;
jhon309 0:1f60ca10b221 13 float Green = 0;
jhon309 0:1f60ca10b221 14 float Blue = 0;
jhon309 0:1f60ca10b221 15
jhon309 0:1f60ca10b221 16 int main()
jhon309 0:1f60ca10b221 17 {
jhon309 0:1f60ca10b221 18 while (1)
jhon309 0:1f60ca10b221 19 {
jhon309 0:1f60ca10b221 20 if(pc.readable())
jhon309 0:1f60ca10b221 21 {
jhon309 0:1f60ca10b221 22 char buffer[128];
jhon309 0:1f60ca10b221 23 pc.gets(buffer, 20);
jhon309 0:1f60ca10b221 24 Red = atof(strtok(buffer, "#"))* variation;
jhon309 0:1f60ca10b221 25 Green = atof(strtok(NULL, "#")) * variation;
jhon309 0:1f60ca10b221 26 Blue = atof(strtok(NULL, "#")) * variation;
jhon309 0:1f60ca10b221 27 printf("%f %f %f \n", Red, Green, Blue);
jhon309 0:1f60ca10b221 28 }
jhon309 0:1f60ca10b221 29 pwmRed.write(Red);
jhon309 0:1f60ca10b221 30 pwmGreen.write(Green);
jhon309 0:1f60ca10b221 31 pwmBlue.write(Blue);
jhon309 0:1f60ca10b221 32 pwmRed.period_ms(1);
jhon309 0:1f60ca10b221 33 pwmGreen.period_ms(1);
jhon309 0:1f60ca10b221 34 pwmBlue.period_ms(1);
jhon309 0:1f60ca10b221 35 }
jhon309 0:1f60ca10b221 36 }