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 16:8eaa5bc2bdb1, committed 2014-02-24
- Comitter:
- DavidEGrayson
- Date:
- Mon Feb 24 01:26:00 2014 +0000
- Parent:
- 15:4df8c50b5e91
- Child:
- 17:2df9861f53ee
- Commit message:
- Got debounced button pressing to work.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GeneralDebouncer.lib Mon Feb 24 01:26:00 2014 +0000 @@ -0,0 +1,1 @@ +GeneralDebouncer#22a56daa5d4f
--- a/buttons.cpp Mon Feb 24 00:21:05 2014 +0000 +++ b/buttons.cpp Mon Feb 24 01:26:00 2014 +0000 @@ -1,8 +1,13 @@ #include <mbed.h> #include "buttons.h" +#include "GeneralDebouncer.h" + +#define BUTTON_DEBOUNCE_TIME 20000 DigitalIn button1(p13); +GeneralDebouncer button1Debouncer(5000); + void buttonsInit() { button1.mode(PullUp); @@ -11,4 +16,28 @@ bool button1IsPressed() { return button1.read() == 0; -} \ No newline at end of file +} + +void button1Montior() +{ + button1Debouncer.update(button1IsPressed()); +} + +bool button1DefinitelyInState(bool state) +{ + button1Montior(); + return button1Debouncer.getState() == state && + button1Debouncer.getTimeInCurrentStateMicroseconds() > BUTTON_DEBOUNCE_TIME; +} + +bool button1DefinitelyPressed() +{ + return button1DefinitelyInState(true); +} + +bool button1DefinitelyReleased() +{ + return button1DefinitelyInState(false); +} + +
--- a/buttons.h Mon Feb 24 00:21:05 2014 +0000 +++ b/buttons.h Mon Feb 24 01:26:00 2014 +0000 @@ -2,4 +2,9 @@ void buttonsInit(); -bool button1IsPressed(); \ No newline at end of file +bool button1IsPressed(); + +void button1Monitor(); + +bool button1DefinitelyPressed(); +bool button1DefinitelyReleased(); \ No newline at end of file
--- a/main.cpp Mon Feb 24 00:21:05 2014 +0000 +++ b/main.cpp Mon Feb 24 01:26:00 2014 +0000 @@ -7,6 +7,7 @@ #include "pc_serial.h" #include "test.h" #include "reckoner.h" +#include "buttons.h" int __attribute__((noreturn)) main() { @@ -15,12 +16,14 @@ // Enable pull-ups on encoder pins and give them a chance to settle. encodersInit(); motorsInit(); + buttonsInit(); // Test routines //testMotors(); //testEncoders(); //testLineSensors(); - testReckoner(); + //testReckoner(); + testButtons(); while(1) {
--- a/test.cpp Mon Feb 24 00:21:05 2014 +0000 +++ b/test.cpp Mon Feb 24 01:26:00 2014 +0000 @@ -10,9 +10,54 @@ #include "pc_serial.h" #include "line_sensors.h" #include "reckoner.h" +#include "buttons.h" + +#include <GeneralDebouncer.h> // tmphax +extern GeneralDebouncer button1Debouncer; // tmphax void printBar(const char * name, uint16_t adcResult); +void testDriveHomoe() +{ + led1 = 1; + +} + +void testButtons() +{ + led1 = 1; + + Pacer reportPacer(100000); + + while(!button1DefinitelyReleased()) + { + if (false && reportPacer.pace()) + { + pc.printf("%1d %11d %11d %11d %11d\r\n", + button1Debouncer.firstReportReceived, + button1Debouncer.maxUpdateIntervalMicroseconds, + button1Debouncer.lastReportTimeMicroseconds, + button1Debouncer.spanBeginTimeMicroseconds, + button1Debouncer.currentState + ); + } + } + while(!button1DefinitelyPressed()) + { + } + led2 = 1; + + while(!button1DefinitelyReleased()); + while(!button1DefinitelyPressed()); + led3 = 1; + + while(!button1DefinitelyReleased()); + while(!button1DefinitelyPressed()); + led4 = 1; + + while(1){}; +} + void testReckoner() { Pacer reportPacer(100000);
--- a/test.h Mon Feb 24 00:21:05 2014 +0000 +++ b/test.h Mon Feb 24 01:26:00 2014 +0000 @@ -4,8 +4,8 @@ void __attribute__((noreturn)) testMotors(); void __attribute__((noreturn)) testLineSensors(); void __attribute__((noreturn)) testReckoner(); - - +void __attribute__((noreturn)) testButtons(); +void __attribute__((noreturn)) testDriveHome(); // These are actually defined in main.h: