Basic motor code

Dependencies:   Motordriver mbed HALLFX_ENCODER Servo

Revision:
6:235548599e79
Parent:
5:7572f73a78f3
Child:
7:6ef9b0aab972
diff -r 7572f73a78f3 -r 235548599e79 main.cpp
--- a/main.cpp	Sat Apr 21 20:09:35 2018 +0000
+++ b/main.cpp	Sat Apr 21 21:22:43 2018 +0000
@@ -2,10 +2,14 @@
 #include "motordriver.h"
 #include "HALLFX_ENCODER.h"
 
+#include <string>
+
 #define SPEED 0.2
 #define TICKSPERREV 390
 #define DISTPERREV 8.25     // 8.25 inches per revolution
 #define TicksPerDeg 2.756
+
+using namespace std;
  
 Motor right(p23,p6,p5, 1); // pwm, fwd, rev
 Motor left(p21, p7, p8, 1); // pwm, fwd, rev
@@ -13,19 +17,23 @@
 HALLFX_ENCODER leftEnc(p15);
 HALLFX_ENCODER rightEnc(p16);
 
-RawSerial  pc(USBTX, USBRX);
-RawSerial  dev(p28,p27);
+RawSerial dev(p13,p14);
+RawSerial pc(USBTX, USBRX);
 DigitalOut led1(LED1);
 DigitalOut led4(LED4);
 
+int count = 0;
+
 void dev_recv()
 {
+    count++;
     led1 = !led1;
     while(dev.readable()) {
         pc.putc(dev.getc());
     }
+    pc.printf("%d", count);
 }
-
+ 
 void pc_recv()
 {
     led4 = !led4;
@@ -34,6 +42,27 @@
     }
 }
 
+string command;
+
+void blue_recv()
+{
+    led1 = !led1;
+    while(dev.readable()) {
+        char letter = (char) dev.getc();
+        command += letter;
+        //strcat(command, &letter);
+        //pc.putc(dev.getc());
+    }
+    pc.printf("%s", command);
+    
+    string circle = "circle";
+    if (circle.compare(0,6,command) == 0) {
+        dev.puts("Recognized word circle");
+    } else {
+        dev.puts("Did not recognize command");
+    }
+}
+
 void stop() {
     right.speed(0.0);
     left.speed(0.0);
@@ -100,9 +129,9 @@
 int main() {
     pc.baud(9600);
     dev.baud(9600);
-
+ 
     pc.attach(&pc_recv, Serial::RxIrq);
-    dev.attach(&dev_recv, Serial::RxIrq);
+    dev.attach(&blue_recv, Serial::RxIrq);
 
     while(1) {
         sleep();