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

main.cpp

Committer:
DavidEGrayson
Date:
2014-02-20
Revision:
1:d0d9653a4547
Parent:
0:e77a0edb9878
Child:
2:968338353aef

File content as of revision 1:d0d9653a4547:

#include <mbed.h>
#include "PololuEncoder.h"
#include "Pacer.h"

DigitalOut led1(LED1), led2(LED2);

Serial pc(USBTX, USBRX);

#define ENCODER1 0x00

PololuEncoderBuffer encoderBuffer;
PololuEncoder encoder1(p6, p7, &encoderBuffer, ENCODER1);

int main() {
    Pacer reportPacer(250000);
    Pacer blinkPacer(200000);
    uint32_t eventCount = 0;    
    while(1) {
        while(encoderBuffer.hasEvents())
        {
            PololuEncoderEvent event = encoderBuffer.readEvent();
            eventCount += 1;
            pc.printf("e %x\n", event);
        }
        if(reportPacer.pace())
        {
            led2 = 1;
            pc.printf("%8x %8x\n", encoder1.getCount(), eventCount);
            led2 = 0;
        }
        if (blinkPacer.pace())
        {
            led1 = !led1;
        }
    }
}