Dependencies: mbed
Fork of 4180lab03_colorpicker by
main.cpp@0:f4d439d30db7, 2017-03-01 (annotated)
- Committer:
- jderemer3
- Date:
- Wed Mar 01 16:37:51 2017 +0000
- Revision:
- 0:f4d439d30db7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jderemer3 | 0:f4d439d30db7 | 1 | #include "mbed.h" |
jderemer3 | 0:f4d439d30db7 | 2 | |
jderemer3 | 0:f4d439d30db7 | 3 | BusOut myled(LED1,LED2,LED3,LED4); |
jderemer3 | 0:f4d439d30db7 | 4 | Serial bluemod(p28,p27); |
jderemer3 | 0:f4d439d30db7 | 5 | PwmOut red(p21); |
jderemer3 | 0:f4d439d30db7 | 6 | PwmOut green(p22); |
jderemer3 | 0:f4d439d30db7 | 7 | PwmOut blue(p23); |
jderemer3 | 0:f4d439d30db7 | 8 | |
jderemer3 | 0:f4d439d30db7 | 9 | int main() |
jderemer3 | 0:f4d439d30db7 | 10 | { |
jderemer3 | 0:f4d439d30db7 | 11 | char bred=0; |
jderemer3 | 0:f4d439d30db7 | 12 | char bgreen=0; |
jderemer3 | 0:f4d439d30db7 | 13 | char bblue=0; |
jderemer3 | 0:f4d439d30db7 | 14 | red = green = blue = 0; |
jderemer3 | 0:f4d439d30db7 | 15 | while(1) { |
jderemer3 | 0:f4d439d30db7 | 16 | if (bluemod.getc()=='!') { |
jderemer3 | 0:f4d439d30db7 | 17 | if (bluemod.getc()=='C') { //color data packet |
jderemer3 | 0:f4d439d30db7 | 18 | bred = bluemod.getc(); // RGB color values |
jderemer3 | 0:f4d439d30db7 | 19 | bgreen = bluemod.getc(); |
jderemer3 | 0:f4d439d30db7 | 20 | bblue = bluemod.getc(); |
jderemer3 | 0:f4d439d30db7 | 21 | if (bluemod.getc()==char(~('!' + 'C' + bred + bgreen + bblue))) { //checksum OK? |
jderemer3 | 0:f4d439d30db7 | 22 | red = bred/255.0; //send new color to RGB LED PWM outputs |
jderemer3 | 0:f4d439d30db7 | 23 | green = bgreen/255.0; |
jderemer3 | 0:f4d439d30db7 | 24 | blue = bblue/255.0; |
jderemer3 | 0:f4d439d30db7 | 25 | } |
jderemer3 | 0:f4d439d30db7 | 26 | } |
jderemer3 | 0:f4d439d30db7 | 27 | } |
jderemer3 | 0:f4d439d30db7 | 28 | } |
jderemer3 | 0:f4d439d30db7 | 29 | } |