Basic motor code

Dependencies:   Motordriver mbed HALLFX_ENCODER Servo

Revision:
5:7572f73a78f3
Parent:
4:a21d15629407
Child:
6:235548599e79
--- a/main.cpp	Sat Apr 21 19:48:25 2018 +0000
+++ b/main.cpp	Sat Apr 21 20:09:35 2018 +0000
@@ -13,6 +13,27 @@
 HALLFX_ENCODER leftEnc(p15);
 HALLFX_ENCODER rightEnc(p16);
 
+RawSerial  pc(USBTX, USBRX);
+RawSerial  dev(p28,p27);
+DigitalOut led1(LED1);
+DigitalOut led4(LED4);
+
+void dev_recv()
+{
+    led1 = !led1;
+    while(dev.readable()) {
+        pc.putc(dev.getc());
+    }
+}
+
+void pc_recv()
+{
+    led4 = !led4;
+    while(pc.readable()) {
+        dev.putc(pc.getc());
+    }
+}
+
 void stop() {
     right.speed(0.0);
     left.speed(0.0);
@@ -61,7 +82,7 @@
     rightEnc.reset();
     right.speed(SPEED);
     float numTicks = 360 * TicksPerDeg;
-    while (rightEnc.read() < numticks) {}
+    while (rightEnc.read() < numTicks) {}
     stop();
     wait(0.1);
 }
@@ -77,12 +98,22 @@
 }
 
 int main() {
+    pc.baud(9600);
+    dev.baud(9600);
+
+    pc.attach(&pc_recv, Serial::RxIrq);
+    dev.attach(&dev_recv, Serial::RxIrq);
+
+    while(1) {
+        sleep();
+    }
     //forward(5.0);
     //turnLeft(90);
-    for (int i = 0; i < 3; i++){
-        forward(5.0);
-        turnLeft(120);
-    }
+    //Should make a triangle
+    //for (int i = 0; i < 3; i++){
+//        forward(5.0);
+//        turnLeft(120);
+//    }
     //manualcheck();
     //forward(10.0);
 }
\ No newline at end of file