Dependencies: mbed
Fork of 4180lab03_colorpicker by
Diff: main.cpp
- Revision:
- 0:f4d439d30db7
diff -r 000000000000 -r f4d439d30db7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Mar 01 16:37:51 2017 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" + +BusOut myled(LED1,LED2,LED3,LED4); +Serial bluemod(p28,p27); +PwmOut red(p21); +PwmOut green(p22); +PwmOut blue(p23); + +int main() +{ + char bred=0; + char bgreen=0; + char bblue=0; + red = green = blue = 0; + while(1) { + if (bluemod.getc()=='!') { + if (bluemod.getc()=='C') { //color data packet + bred = bluemod.getc(); // RGB color values + bgreen = bluemod.getc(); + bblue = bluemod.getc(); + if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) { //checksum OK? + red = bred/255.0; //send new color to RGB LED PWM outputs + green = bgreen/255.0; + blue = bblue/255.0; + } + } + } + } +} \ No newline at end of file