CSCI 5360 JB_MB_BC
/
m3pi_reciever
Executes commands received via xbee.
Diff: main.cpp
- Revision:
- 0:98be52da5242
- Child:
- 1:8b83b8a03351
diff -r 000000000000 -r 98be52da5242 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Apr 19 16:01:27 2015 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "m3pi.h" + +Serial xbee(p28, p27); +m3pi m3pi; + +void execute(); +void set_command(); + +const char LEFT = 'A'; +const char RIGHT = 'B'; +const char STOP = 'D'; +const char FORWARD = 'E'; +const char BACKWARD = 'F'; + +char command; +float speed; + +int main() { + + command = STOP; + speed = 0.3; + m3pi.locate(0,1); + m3pi.printf("Hola"); + + while (1) { + set_command(); + m3pi.locate(0,1); + m3pi.printf("%c",command); + execute(); + //wait(1); + } +} + +void execute() { + switch (command) { + case LEFT: + m3pi.left(speed); break; + case RIGHT: + m3pi.right(speed); break; + case STOP: + m3pi.stop(); break; + case FORWARD: + m3pi.forward(speed); break; + case BACKWARD: + m3pi.backward(speed); break; + } +} + +void set_command() { + if (xbee.readable()) { + command = xbee.getc(); + wait(1); + } +} \ No newline at end of file