New xbee sent protocol
Dependencies: mbed C12832 XBee
Diff: main.cpp
- Revision:
- 0:ce2085295a51
- Child:
- 1:9ffff91aeeb2
diff -r 000000000000 -r ce2085295a51 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Mar 10 14:20:19 2016 +0000 @@ -0,0 +1,84 @@ +#include "mbed.h" + +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +DigitalIn down(p12); +DigitalIn left(p13); +DigitalIn up(p15); +DigitalIn right(p16); + +Serial xbee(p9,p10); + +char Source=0b00000010; +char Des,Item,Status,Checksum; + + + +void send(){ + xbee.putc(0x7E); + myled1=1; + wait(0.01); + xbee.putc(Source); + myled2=1; + wait(0.01); + xbee.putc(Des); + myled3=1; + wait(0.01); + xbee.putc(Item); + myled4=1; + wait(0.01); + xbee.putc(Status); + myled1=0; + wait(0.01); + xbee.putc(Checksum); + myled2=0; + wait(0.1); + xbee.putc(0x7E); + myled3=0; + wait(0.1); + xbee.putc(0xD); + myled4=0; +} + +int main() { + while(1) { + xbee.baud(57600); + if(up&&!left&&!right){ + myled1 = 1; + } + if(up&&right){ + myled1=1; + myled2=1; + } + if(right&&!up&&!down){ + myled2 = 1; + } + if(down&&right){ + myled2=1; + myled3=1; + } + if(down&&!left&&!right){ + myled3 = 1; + } + if(down&&left){ + myled3=1; + myled4=1; + } + if(left&&!up&&!down){ + myled4 = 1; + } + if(up&&left){ + myled1=1; + myled4=1; + } + wait(0.2); + myled1=0; + myled2=0; + myled3=0; + myled4=0; + send(); + } +}