David Grayson / Mbed 2 deprecated DeadReckoning

Dependencies:   PololuEncoder Pacer mbed GeneralDebouncer

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers line_sensors.cpp Source File

line_sensors.cpp

00001 #include "line_sensors.h"
00002 
00003 DigitalInOut lineSensorsDigital[LINE_SENSOR_COUNT] = {
00004     DigitalInOut(p18), // white wire, left-most sensor
00005     DigitalInOut(p19), // orange wire, middle sensor
00006     DigitalInOut(p20), // brown wire, right-most sensor
00007 };
00008 
00009 void readSensors(uint16_t * values)
00010 {
00011     for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++)
00012     {
00013         values[i] = 1000;
00014         lineSensorsDigital[i].mode(PullNone);
00015         lineSensorsDigital[i].output();
00016         lineSensorsDigital[i].write(1);
00017     }
00018     
00019     wait_us(10);
00020     
00021     Timer timer;
00022     timer.start();
00023 
00024     for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++)
00025     {
00026         lineSensorsDigital[i].input();
00027     }
00028 
00029     while(timer.read_us() < 1000)
00030     {
00031         for(uint8_t i = 0; i < LINE_SENSOR_COUNT; i++)
00032         {
00033             if (values[i] == 1000 && lineSensorsDigital[i].read() == 0)
00034             {
00035                 values[i] = timer.read_us();   
00036             }
00037         }
00038     }
00039 }