From 878f86bf1cffb836853b6c6e487b9dda28c49ad2 Mon Sep 17 00:00:00 2001 From: James Myatt Date: Tue, 25 Aug 2020 13:54:33 +0100 Subject: [PATCH] Add isPressed and getPressedState methods --- src/Bounce2.h | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/Bounce2.h b/src/Bounce2.h index 44d43d4..4032a70 100644 --- a/src/Bounce2.h +++ b/src/Bounce2.h @@ -267,22 +267,34 @@ protected: stateForPressed = state; } + /*! + @brief Get the electrical state (HIGH/LOW) that corresponds to a physical press. + */ + inline bool getPressedState() { + return stateForPressed; + }; + + /*! + @brief Returns true if the button is currently physically pressed. + */ + inline bool isPressed() { + return read() == getPressedState(); + }; + /*! @brief Returns true if the button was physically pressed */ - bool pressed() { - return changed() && (read() == stateForPressed); + inline bool pressed() { + return changed() && isPressed(); }; /*! @brief Returns true if the button was physically released */ - bool released() { - return changed() && (read() != stateForPressed); + inline bool released() { + return changed() && !isPressed(); }; - - }; #endif