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
UI/Buttons/Buttons.cpp@0:a6a169de725f, 2013-05-27 (annotated)
- Committer:
- shimniok
- Date:
- Mon May 27 13:26:03 2013 +0000
- Revision:
- 0:a6a169de725f
- Child:
- 9:39c0ff43332b
Working version with priorities set and update time display
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shimniok | 0:a6a169de725f | 1 | #include "Buttons.h" |
shimniok | 0:a6a169de725f | 2 | #include "PinDetect.h" |
shimniok | 0:a6a169de725f | 3 | |
shimniok | 0:a6a169de725f | 4 | PinDetect nextButton(p14); |
shimniok | 0:a6a169de725f | 5 | PinDetect selectButton(p16); // Input selectButton |
shimniok | 0:a6a169de725f | 6 | PinDetect prevButton(p15); |
shimniok | 0:a6a169de725f | 7 | |
shimniok | 0:a6a169de725f | 8 | Buttons::Buttons(void): which(0), pressed(false) |
shimniok | 0:a6a169de725f | 9 | { |
shimniok | 0:a6a169de725f | 10 | } |
shimniok | 0:a6a169de725f | 11 | |
shimniok | 0:a6a169de725f | 12 | void Buttons::init() |
shimniok | 0:a6a169de725f | 13 | { |
shimniok | 0:a6a169de725f | 14 | |
shimniok | 0:a6a169de725f | 15 | // Set up button (plugs into two GPIOs, active low |
shimniok | 0:a6a169de725f | 16 | selectButton.mode(PullUp); |
shimniok | 0:a6a169de725f | 17 | selectButton.setSamplesTillAssert(50); |
shimniok | 0:a6a169de725f | 18 | selectButton.setAssertValue(0); // active low logic |
shimniok | 0:a6a169de725f | 19 | selectButton.setSampleFrequency(50); // us |
shimniok | 0:a6a169de725f | 20 | selectButton.attach_asserted( this, &Buttons::selectPressed ); |
shimniok | 0:a6a169de725f | 21 | |
shimniok | 0:a6a169de725f | 22 | nextButton.mode(PullUp); |
shimniok | 0:a6a169de725f | 23 | nextButton.setSamplesTillAssert(50); |
shimniok | 0:a6a169de725f | 24 | nextButton.setAssertValue(0); // active low logic |
shimniok | 0:a6a169de725f | 25 | nextButton.setSampleFrequency(50); // us |
shimniok | 0:a6a169de725f | 26 | nextButton.attach_asserted( this, &Buttons::nextPressed ); |
shimniok | 0:a6a169de725f | 27 | |
shimniok | 0:a6a169de725f | 28 | prevButton.mode(PullUp); |
shimniok | 0:a6a169de725f | 29 | prevButton.setSamplesTillAssert(50); |
shimniok | 0:a6a169de725f | 30 | prevButton.setAssertValue(0); // active low logic |
shimniok | 0:a6a169de725f | 31 | prevButton.setSampleFrequency(50); // us |
shimniok | 0:a6a169de725f | 32 | prevButton.attach_asserted( this, &Buttons::prevPressed ); |
shimniok | 0:a6a169de725f | 33 | } |
shimniok | 0:a6a169de725f | 34 | |
shimniok | 0:a6a169de725f | 35 | void Buttons::nextPressed() |
shimniok | 0:a6a169de725f | 36 | { |
shimniok | 0:a6a169de725f | 37 | pressed = true; |
shimniok | 0:a6a169de725f | 38 | which = NEXT_BUTTON; |
shimniok | 0:a6a169de725f | 39 | } |
shimniok | 0:a6a169de725f | 40 | |
shimniok | 0:a6a169de725f | 41 | void Buttons::prevPressed() |
shimniok | 0:a6a169de725f | 42 | { |
shimniok | 0:a6a169de725f | 43 | pressed = true; |
shimniok | 0:a6a169de725f | 44 | which = PREV_BUTTON; |
shimniok | 0:a6a169de725f | 45 | } |
shimniok | 0:a6a169de725f | 46 | |
shimniok | 0:a6a169de725f | 47 | void Buttons::selectPressed() |
shimniok | 0:a6a169de725f | 48 | { |
shimniok | 0:a6a169de725f | 49 | pressed = true; |
shimniok | 0:a6a169de725f | 50 | which = SELECT_BUTTON; |
shimniok | 0:a6a169de725f | 51 | } |