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:
31:739b91331f31
Parent:
29:cfcf08d8ac79
Child:
32:83a13b06093c
--- a/line_sensors.cpp	Tue Mar 04 02:09:54 2014 +0000
+++ b/line_sensors.cpp	Tue Mar 04 03:04:00 2014 +0000
@@ -1,11 +1,53 @@
 #include "line_sensors.h"
 
+
+/**
 AnalogIn lineSensorsAnalog[LINE_SENSOR_COUNT] = {
     AnalogIn(p20), // brown wire, left-most sensor
     AnalogIn(p19), // orange wire, middle sensor
     AnalogIn(p17), // blue wire, right-most sensor
+};  // TODO: remove
+**/
+
+DigitalInOut lineSensorsDigital[LINE_SENSOR_COUNT] = {
+    DigitalInOut(p18), // brown wire, left-most sensor
+    DigitalInOut(p19), // orange wire, middle sensor
+    DigitalInOut(p20), // blue wire, right-most sensor
 };
 
+void readSensors(uint16_t * values)
+{
+    for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++)
+    {
+        values[i] = 1000;
+        lineSensorsDigital[i].mode(PullNone);
+        lineSensorsDigital[i].output();
+        lineSensorsDigital[i].write(1);
+    }
+    
+    wait_us(10);
+    
+    Timer timer;
+    timer.start();
+
+    for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++)
+    {
+        lineSensorsDigital[i].input();
+    }
+
+    while(timer.read_us() < 1000)
+    {
+        for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++)
+        {
+            if (values[i] == 1000 && lineSensorsDigital[i].read() == 0)
+            {
+                values[i] = timer.read_us();   
+            }
+        }
+    }
+}
+
+
 /**
 uint16_t analogReadWithFilter(AnalogIn * input)
 {