Executes commands received via xbee.

Dependencies:   m3pi mbed

Files at this revision

API Documentation at this revision

Comitter:
bc6599
Date:
Sun Apr 19 16:01:27 2015 +0000
Child:
1:8b83b8a03351
Commit message:
Initial commit

Changed in this revision

m3pi.lib Show annotated file Show diff for this revision Revisions of this file
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/m3pi.lib	Sun Apr 19 16:01:27 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/chris/code/m3pi/#4b7d6ea9b35b
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Apr 19 16:01:27 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889
\ No newline at end of file