
1st Version of LiveXboxRobot. Mbed connected to PC.
Revision 0:b1015ef37a9e, committed 2016-04-28
- Comitter:
- GuillaumeMrzo
- Date:
- Thu Apr 28 12:11:44 2016 +0000
- Commit message:
- 1st Version of LiveXboxRobot project. PC side.
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 Apr 28 12:11:44 2016 +0000 @@ -0,0 +1,133 @@ +#include "mbed.h" +#include "stdio.h" + +Serial pc(USBTX, USBRX); +DigitalOut myled(LED3);//Create variable for Led 3 on the mbed + +// Character from the keyboard +char key; + +// xbee +char X; +DigitalOut rst1(p8); +Serial xbee(p9, p10); +DigitalOut rst(p8); + + +// LEDs +DigitalOut ledL(LED1); +DigitalOut ledR(LED4); + + +// -------------------- Callback Xbee receive ---------------------- // +void xbee_recv(){ + while(xbee.readable()) { + if(xbee.getc() == 'R'){ + pc.printf("R%i\r\n", xbee.getc()); + } + if(xbee.getc() == 'L'){ + pc.printf("L%i\r\n", xbee.getc()); + } + } +} + + + +// -------------------- Callback PC ---------------------- // +void pc_recv(){ + + key=pc.getc(); + + //If the keypress was an arrow key + if(key==0x1B) { + key = pc.getc(); + if (key == 0x5B) { //Check again! + key = pc.getc(); + switch(key) { //Check to see which arrow key... + case 0x41: + pc.putc('U'); + xbee.putc('U'); + break; + case 0x42: + pc.putc('D'); + xbee.putc('D'); + break; + case 0x43: + pc.putc('R'); + xbee.putc('R'); + break; + case 0x44: + pc.putc('L'); + xbee.putc('L'); + break; + } + } + } + else{ + switch (key) { + case '1': // key 1 + xbee.putc(key); + break; + case '2': // key 2 + xbee.putc(key); + break; + case '3': // key 3 + xbee.putc(key); + pc.putc(key); + break; + case '4': // key 4 + xbee.putc(key); + break; + case 'U': // key U / GUI up + xbee.putc(key); + pc.putc(key); + break; + case 'D': // key D / GUI down + xbee.putc(key); + break; + case 'L': // key L / GUI left + xbee.putc(key); + break; + case 'R': // key R / GUI right + xbee.putc(key); + break; + case 'A': // key U / GUI right + xbee.putc(key); + break; + case 'B': // key D / GUI right + xbee.putc(key); + break; + case 'C': // key L / GUI right + xbee.putc(key); + break; + case 'E': // key R / GUI right + xbee.putc(key); + break; + default: + break; + } + } +} + + +// -------------------- Callback XBox controller ---------------------- // + + + + +int main() { + + // Initialize Xbee + rst1 = 0; + wait_ms(1); + rst1 = 1; + wait_ms(1); + + pc.attach(&pc_recv, Serial::RxIrq); + xbee.attach(&xbee_recv, Serial::RxIrq); + + while(1){ + wait_ms(1); + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Apr 28 12:11:44 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/aae6fcc7d9bb \ No newline at end of file