Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setPin() function #91

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add setPin() function
Add setPin() function, must set/change GPIO pin before calling begin().
prakai committed Mar 2, 2024
commit 4452c72a6a93cab6bcf454323502fc2bef5fb4c1
8 changes: 8 additions & 0 deletions src/EasyButton.cpp
Original file line number Diff line number Diff line change
@@ -7,6 +7,14 @@

#include "EasyButton.h"

void EasyButton::setPin(uint8_t pin)
{
if (_time == 0)
{
_pin = pin;
}
}

void EasyButton::begin()
{
pinMode(_pin, _pu_enabled ? INPUT_PULLUP : INPUT);
1 change: 1 addition & 0 deletions src/EasyButton.h
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ class EasyButton : public EasyButtonBase
~EasyButton() {}

// PUBLIC FUNCTIONS
virtual void setPin(uint8_t pin); // Set/Change GPIO pin, must set/change before calling begin().
virtual void begin(); // Initialize a button object and the pin it's connected to.
bool read(); // Returns the current debounced button state, true for pressed, false for released.
void update(); // Update button pressed time, only needed when using interrupts.