David's dead reckoning code for the LVBots competition on March 6th. Uses the mbed LPC1768, DRV8835, QTR-3RC, and two DC motors with encoders.

Dependencies:   PololuEncoder Pacer mbed GeneralDebouncer

Revision:
10:e4dd36148539
Parent:
9:9734347b5756
Child:
12:835a4d24ae3b
--- a/test.cpp	Sat Feb 22 03:03:37 2014 +0000
+++ b/test.cpp	Sat Feb 22 04:44:44 2014 +0000
@@ -8,11 +8,42 @@
 #include "leds.h"
 #include "encoders.h"
 #include "pc_serial.h"
+#include "line_sensors.h"
+
+void printBar(const char * name, uint16_t adcResult);
+
+void testLineSensors()
+{
+    led1 = 1;
+    Pacer reportPacer(100000);
+    bool const printBarGraph = true;
+    while (1)
+    {
+        if (reportPacer.pace())
+        {
+            uint16_t left = lineSensorsAnalog[0].read_u16();
+            uint16_t middle = lineSensorsAnalog[1].read_u16();
+            uint16_t right = lineSensorsAnalog[2].read_u16();
+            
+            if (printBarGraph)
+            {
+                pc.printf("\x1B[0;0H");  // VT100 command for "go to 0,0"
+                printBar("L", left);
+                printBar("M", middle);
+                printBar("R", right);
+            }
+            else
+            {
+                pc.printf("%8d %8d %8d\n", left, middle, right);
+            }
+        }
+    }
+}
 
 void testEncoders()
 {
     Pacer reportPacer(500000);
-    Pacer blinkPacer(200000);
+    led1 = 1;
     while(1)
     {
         while(encoderBuffer.hasEvents())
@@ -25,12 +56,7 @@
             led2 = 1;
             pc.printf("%8d %8d\n", encoderLeft.getCount(), encoderRight.getCount());
             led2 = 0;
-        }
-        
-        if (blinkPacer.pace())
-        {
-            led1 = !led1;
-        }
+       }
     }
 }
 
@@ -66,4 +92,15 @@
         motorsSpeedSet(1200, 1200);
         wait(2);
     }
+}
+
+void printBar(const char * name, uint16_t adcResult)
+{
+    pc.printf("%-2s %5d |", name, adcResult);
+    uint8_t width = adcResult >> 10;
+    uint8_t i;
+    for(i = 0; i < width; i++){ pc.putc('#'); }
+    for(; i < 63; i++){ pc.putc(' '); }
+    pc.putc('|');
+    pc.putc('\n');
 }
\ No newline at end of file