David's line following code from the LVBots competition, 2015.

Dependencies:   GeneralDebouncer Pacer PololuEncoder mbed

Fork of DeadReckoning by David Grayson

Files at this revision

API Documentation at this revision

Comitter:
DavidEGrayson
Date:
Thu Feb 20 20:09:40 2014 +0000
Parent:
1:d0d9653a4547
Child:
3:59c80d4b4bf2
Commit message:
Moved the code to enable pull-ups into the app.

Changed in this revision

PololuEncoder.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/PololuEncoder.lib	Thu Feb 20 18:55:04 2014 +0000
+++ b/PololuEncoder.lib	Thu Feb 20 20:09:40 2014 +0000
@@ -1,1 +1,1 @@
-PololuEncoder#138f5421c287
+PololuEncoder#22ac2b4a8012
--- a/main.cpp	Thu Feb 20 18:55:04 2014 +0000
+++ b/main.cpp	Thu Feb 20 20:09:40 2014 +0000
@@ -8,10 +8,22 @@
 
 #define ENCODER1 0x00
 
+const PinName encoderPin1A = p6,
+              encoderPin1B = p7;
+
 PololuEncoderBuffer encoderBuffer;
-PololuEncoder encoder1(p6, p7, &encoderBuffer, ENCODER1);
+PololuEncoder encoder1(encoderPin1A, encoderPin1B, &encoderBuffer, ENCODER1);
 
-int main() {
+int main()
+{
+    pc.baud(115200);
+    
+    // Enable pull-ups on encoder pins and give them a chance to settle.
+    DigitalIn(encoderPin1A).mode(PullUp);
+    DigitalIn(encoderPin1B).mode(PullUp);
+    wait_us(50);
+    encoder1.init();
+
     Pacer reportPacer(250000);
     Pacer blinkPacer(200000);
     uint32_t eventCount = 0;    
@@ -20,14 +32,17 @@
         {
             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);
+            char str[80];
+            sprintf(str, "%8x %8x\n", encoder1.getCount(), eventCount);
+            pc.puts(str);
             led2 = 0;
         }
+        
         if (blinkPacer.pace())
         {
             led1 = !led1;