Comments (3)
Glad that it fixed your problem.
I made a somewhat conscious decision to decouple the configuration of the hardware from the AceButton library. The library doesn't really care whether you are using an internal pull-up or an external pull-up resistor. It just needs to know the logical value of the button in the default (unpressed) state. If the library handled the call to pinMode()
, it would make the initialization sequence of the button slightly more complicated, since we now need a mechanism to tell the button how it is wired (3 different ways: internal pullup, external pullup, external pull-down). It also seemed to me that most people would want explicit control over the initialization of the hardware pins (and various other hardware connected to the microcontroller), instead of having the library perform that invisibly. Maybe they don't want the pins to be configured at setup()
, maybe they want it to be configured dynamically at a later point in their application, and maybe they want it to be turned off when something happens. Since the AceButton library does not care about the hardware configuration, and I cannot anticipate all possible application scenarios, it didn't seem appropriate to have the library handle this.
I think all my examples in the README.md contain a call to pinMode()
, so I would have thought that it would be sufficient. But since you were confused by this, it's likely that other people might be confused. I will add a blurb in the README.md to say that the pinMode()
must be called explicitly for each button.
from acebutton.
Hi,
Without seeing your hardware setup, I can only make educated guesses. From your posted code, my guess is that you forgot to call the pinMode(LEFT_PEDAL, INPUT_PULLUP)
method in your setup()
. Recall that an Arduino board starts up with its pins in INPUT
mode, not INPUT_PULLUP
(see https://www.arduino.cc/en/Tutorial/DigitalPins). This means that the pin is in a high impedance state, so that if there is no wire connected to the pin, its voltage level is floating. The logical level of a floating input pin will be completely random. You need to connect an external pullup resistor (so that the button reads HIGH
when there is nothing connected to the pin). OR, call pinMode(LEFT_PEDAL, INPUT_PULLUP)
in the setup method to tell the microcontroller to enable the internal pull up resistor on the specified pin.
I think the reason your first sample code works is that you make a call todigitalWrite(button, HIGH)
. My understanding is that this is an old (potentially deprecated?) method of setting the pin into an INPUT_PULLUP
mode.
For a problem like this, I recommend going to one of the example code that I provided in the examples/
folder. A good one is examples/SingleButton/SingleButton.ino
. Try running it exactly as is, with no changes (except maybe the pin number), and verify that it works. Then take a look at another example that uses the kEventRepeatPressed
event, i.e. examples/TunerButtons/TunerButtons.ino
, and incrementally add the various lines of code to implement your leftPedal
button.
Hope this helps.
from acebutton.
Thanks for the reply! I just read "handles both pull-up and pull-down wiring" in the Readme and in the docs I read "When using a pullup resistor (either external or internal) and the button is connected to ground, this should be set to HIGH.". That lead me to assume that the library would take care of setting the internal pull-up resistor.
Edit:
I just tested it with pinMode(LEFT_PEDAL, INPUT_PULLUP);
and that totally solved the problem.
Thank you so much. Maybe it would make sense to actually handle that within the library or to change the Readme to say something like "compatible with both pull-up and pull-down wiring" instead of "handles both pull-up and pull-down wiring". Or is it just me who thinks this is confusing?
from acebutton.
Related Issues (20)
- Possible conflict with TC3 library on SAMD21 architecture ?
- can it be used with a SN74HC165 is a 8-Bit Parallel-Load Shift Registers
- arduion libray issues HOT 2
- Code_ESP32_Blynk_Bluetooth_WiFi_Switch_control_8_Relays_02.ino:27:21: error: variable or field 'button1Handler' declared void
- Suggestion for implementing 'setLongReleasedDelay' HOT 1
- use of __FlashStringHelper is ambiguous HOT 7
- Remote inputs HOT 2
- call of overloaded AceButton(int) is ambiguous HOT 1
- call of overloaded 'init(int)' is ambiguous HOT 1
- Capacitive button returns release while button is pressed HOT 2
- [OT] featuring AceButton HOT 2
- Public method to supress long kEventLongPressed HOT 10
- Tri-state button example HOT 2
- No longer responding to single click HOT 1
- Examples depend on "using namespace ace_button" in the global namespace
- How can I use it with port extender?
- I want to set setDefaultReleasedState to LOW
- ESP32 Support? HOT 1
- Could we make `isLongPressed()` public?
- Two button both pressed (sample LongPress)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acebutton.