Code for autonomous rover for Sparkfun AVC. DataBus won 3rd in 2012 and the same code was used on Troubled Child, a 1986 Jeep Grand Wagoneer to win 1st in 2014.
Dependencies: mbed Watchdog SDFileSystem DigoleSerialDisp
Diff: UI/Buttons/Buttons.cpp
- Revision:
- 0:a6a169de725f
- Child:
- 9:39c0ff43332b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI/Buttons/Buttons.cpp Mon May 27 13:26:03 2013 +0000 @@ -0,0 +1,51 @@ +#include "Buttons.h" +#include "PinDetect.h" + +PinDetect nextButton(p14); +PinDetect selectButton(p16); // Input selectButton +PinDetect prevButton(p15); + +Buttons::Buttons(void): which(0), pressed(false) +{ +} + +void Buttons::init() +{ + + // Set up button (plugs into two GPIOs, active low + selectButton.mode(PullUp); + selectButton.setSamplesTillAssert(50); + selectButton.setAssertValue(0); // active low logic + selectButton.setSampleFrequency(50); // us + selectButton.attach_asserted( this, &Buttons::selectPressed ); + + nextButton.mode(PullUp); + nextButton.setSamplesTillAssert(50); + nextButton.setAssertValue(0); // active low logic + nextButton.setSampleFrequency(50); // us + nextButton.attach_asserted( this, &Buttons::nextPressed ); + + prevButton.mode(PullUp); + prevButton.setSamplesTillAssert(50); + prevButton.setAssertValue(0); // active low logic + prevButton.setSampleFrequency(50); // us + prevButton.attach_asserted( this, &Buttons::prevPressed ); +} + +void Buttons::nextPressed() +{ + pressed = true; + which = NEXT_BUTTON; +} + +void Buttons::prevPressed() +{ + pressed = true; + which = PREV_BUTTON; +} + +void Buttons::selectPressed() +{ + pressed = true; + which = SELECT_BUTTON; +}