diff options
author | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-05 18:13:20 -0400 |
---|---|---|
committer | Marti Bolivar <mbolivar@leaflabs.com> | 2012-06-07 03:38:30 -0400 |
commit | 947caf8be9d94713d012443f950e148f8fa6e7c8 (patch) | |
tree | 9d2b6c60e4d0a21414c2f6ac558f2571a357d4c9 /wirish | |
parent | 66167fcf43fabbf33a1ea357954a433cee4a76ff (diff) | |
download | librambutan-947caf8be9d94713d012443f950e148f8fa6e7c8.tar.gz librambutan-947caf8be9d94713d012443f950e148f8fa6e7c8.zip |
isButtonPressed(): Take a pin and pressedLevel argument.
This allows dealing with push-buttons on pins other than
BOARD_BUTTON_PIN.
Signed-off-by: Marti Bolivar <mbolivar@leaflabs.com>
Diffstat (limited to 'wirish')
-rw-r--r-- | wirish/include/wirish/io.h | 3 | ||||
-rw-r--r-- | wirish/wirish_digital.cpp | 6 |
2 files changed, 5 insertions, 4 deletions
diff --git a/wirish/include/wirish/io.h b/wirish/include/wirish/io.h index b5fe3a8..08bbc06 100644 --- a/wirish/include/wirish/io.h +++ b/wirish/include/wirish/io.h @@ -181,7 +181,8 @@ static inline void toggleLED() { * * @see pinMode() */ -uint8 isButtonPressed(); +uint8 isButtonPressed(uint8 pin=BOARD_BUTTON_PIN, + uint32 pressedLevel=BOARD_BUTTON_PRESSED_LEVEL); /** * Wait until the button is pressed and released, timing out if no diff --git a/wirish/wirish_digital.cpp b/wirish/wirish_digital.cpp index 05ce756..2711a33 100644 --- a/wirish/wirish_digital.cpp +++ b/wirish/wirish_digital.cpp @@ -64,10 +64,10 @@ void togglePin(uint8 pin) { #define BUTTON_DEBOUNCE_DELAY 1 -uint8 isButtonPressed() { - if (digitalRead(BOARD_BUTTON_PIN) == BOARD_BUTTON_PRESSED_LEVEL) { +uint8 isButtonPressed(uint8 pin, uint32 pressedLevel) { + if (digitalRead(pin) == pressedLevel) { delay(BUTTON_DEBOUNCE_DELAY); - while (digitalRead(BOARD_BUTTON_PIN) == BOARD_BUTTON_PRESSED_LEVEL) + while (digitalRead(pin) == pressedLevel) ; return true; } |