We wrote this for controlling our bots in a game designed for the ARM design challenge

Dependencies:   Motor Robo mbed

Files at this revision

API Documentation at this revision

Comitter:
narendraj9
Date:
Sun Oct 27 09:19:15 2013 +0000
Commit message:
initial commit

Changed in this revision

Motor.lib Show annotated file Show diff for this revision Revisions of this file
Robo.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
diff -r 000000000000 -r 2f73cbc3f754 Motor.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Motor.lib	Sun Oct 27 09:19:15 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/narendraj9/code/Motor/#118c5f0675da
diff -r 000000000000 -r 2f73cbc3f754 Robo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Robo.lib	Sun Oct 27 09:19:15 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/narendraj9/code/Robo/#c31299ed92f1
diff -r 000000000000 -r 2f73cbc3f754 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Oct 27 09:19:15 2013 +0000
@@ -0,0 +1,91 @@
+#include "mbed.h"
+#include "Robo.h"
+
+
+// robot object
+Robo roger(p20, p19, p18,
+           p21, p22, p23,
+           p24, p25, p27, p28, p29, p30);
+
+DigitalOut myled(LED2); 
+DigitalOut left(LED3);  // status left LED 
+DigitalOut right(LED4); // status right LED
+
+// a buzzer when a life decreses
+DigitalOut buzzer(p7);
+
+//the rf receiver Serial object
+Serial rx(p9, p10);
+
+//a rise on this pin reduces a life of the robot
+InterruptIn heart(p6);
+
+/* a wrapper function for roger.devLives
+ * which can be passed as argument to some other funtion
+ */
+void decRoboLives() {
+    roger.decLives();
+    buzzer = 0;
+ }
+
+int main() {
+    char command = 'S';
+    rx.baud(2400);
+    myled = 1; // test led. test: program loaded successfully
+    heart.rise(decRoboLives);
+
+/* main while loop 
+ * 1. wait for instructions
+ * 1. read instruction
+ * 2. do the required action
+ * 3. empty the rx object by reading further
+ * 4. go to 1
+ *  we introduced redundancy in sending the instructions so as to make
+ * sure they really end up being received by the robots. that's the raison d'etre
+ * for step 3.
+ */
+    while(1) {
+        if (rx.readable()) {
+            command = rx.getc();
+            switch(command) {
+                case 'L' :
+                    left = 1;
+                    right = 0;
+                    roger.goLeft();
+                    break;
+                case 'R':
+                    right = 1;
+                    left = 0;
+                    roger.moveRight();
+                    break;
+                case 'M':
+                    roger.goAhead();
+                    break;
+                case 'B':
+                    roger.moveBack();
+                    break;
+                case 'S':
+                    roger.stop();
+                    break;
+                case 'D':
+                    roger.printlcd("Hi");
+                    wait(1);
+                    roger.goLeft();
+                    roger.moveRight();
+                    roger.goLeft();
+                    roger.moveRight();
+                    roger.goAhead();
+                    wait(1);
+                    roger.moveBack();
+                    wait(1);
+                    roger.stop();
+                default:
+                    roger.printlcd("Waiting...      ");
+                    break;
+             
+            }
+            while (rx.readable())
+                command = rx.getc();
+        }
+    }
+ }
diff -r 000000000000 -r 2f73cbc3f754 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Oct 27 09:19:15 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file