Executes commands received via xbee.

Dependencies:   m3pi mbed

main.cpp

Committer:
bc6599
Date:
2015-04-19
Revision:
0:98be52da5242
Child:
1:8b83b8a03351

File content as of revision 0:98be52da5242:

#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);
    }
}