Dependencies:   mbed

Fork of 4180lab03_colorpicker by Jeremy Deremer

main.cpp

Committer:
jderemer3
Date:
2017-03-01
Revision:
0:f4d439d30db7

File content as of revision 0:f4d439d30db7:

#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;
                }
            }
        }
    }
}