mathertel / OneButton

An Arduino library for using a single button for multiple purpose input.
http://www.mathertel.de/Arduino/OneButtonLibrary.aspx
Other
918 stars 229 forks source link

How to get rid of #define PIN_INPUT? #143

Open mister-Monk opened 1 week ago

mister-Monk commented 1 week ago

I want to use the GPIO number obtained from SPIFFS in OneButton. Something like this:

include

include

void setup() { File _file = SPIFFS.open ... BUTTON_pin = r_c.toInt(); ... OneButton button1(BUTTON_pin, true, true); }

Is this possible? How?

mister-Monk commented 1 week ago

This is what I did:

Added a copy OneButton::OneButton to the library

void initOB(const int pin, const boolean activeLow = true, const bool pullupActive = true);

void OneButton::initOB(const int pin, const boolean activeLow, const bool pullupActive) { // OneButton(); _pin = pin;

if (activeLow) { // the button connects the input pin to GND when pressed. _buttonPressed = LOW; ...

Further

include

include

OneButton button1;

void setup() { File _file = SPIFFS.open ... BUTTON_pin = r_c.toInt(); ... button1.initOB(BUTTON_pin, true, true); }

It works. But I'm not sure if this is the right way.