Danius Kalvaitis
/
danBed_communicate
Communicate with danBed via UART
Revision 0:fc1ff02f51e1, committed 2015-02-12
- Comitter:
- DaniusKalv
- Date:
- Thu Feb 12 12:34:29 2015 +0000
- Child:
- 1:1d18a2a3e9a0
- Commit message:
- Initial commit
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 12 12:34:29 2015 +0000 @@ -0,0 +1,89 @@ +#include "mbed.h" +#include <string> + +PwmOut RED(LED1); +PwmOut BLUE(LED2); +PwmOut GREEN(LED3); +DigitalOut RGB(LED4); + +//Serial pc(p28, p27); +Serial pc(USBTX, USBRX); + +void receive(); +char temp[100]; + +int main() { + + RED = 1; + GREEN = 1; + BLUE = 1; + RGB = 0; + + pc.baud(115200); + + pc.printf("\r\nWelcome to danBed communication v1.0!"); + pc.printf("\r\nWrite 'Labas' to continue...\r\n"); + + GET: + receive(); + string labas = "Labas"; + + if (temp == labas) pc.printf("\r\nLabas!!!\r\n"); + else{ + pc.printf("\r\nTry again! Type 'Labas'...\r\n"); + goto GET; + } + + delete &labas; + + while(1) { + + receive(); + char buffer[20]; + float value; + + //sscanf(temp,"%s %f", buffer, &value); + for(int j = 0; j < 10; j++) pc.printf("\r\n%i", buffer[j]); + + if(buffer == "RGB"){ + RGB = value; + if(value == 1) pc.printf("\r\nRGB turned ON\r\n"); + else pc.printf("\r\nRGB turned OFF\r\n"); + } + else if(buffer == "RED"){ + RED = value; + pc.printf("\r\nRED value %0.2f\r\n", value); + } + else if(buffer == "GREEN"){ + GREEN = value; + pc.printf("\r\nGREEN value %0.2f\r\n", value); + } + else if(buffer == "BLUE"){ + BLUE = value; + pc.printf("\r\nBLUE value %0.2f\r\n", value); + } + else pc.printf("\r\nCommand not recognised!\r\n"); + //else if(receiver == "RED"){ + //pc.gets( + } +} + +void receive(){ + memset(temp, 255, sizeof(temp)); + char c; + + int i = 0; + + while(true){ + if(pc.readable()){ + c = pc.getc(); + if (c == 13){ + temp[i] = 0; + break; + } + else temp[i] = c; + pc.putc(c); + i++; + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 12 12:34:29 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file