GithubHelp home page GithubHelp logo

Comments (3)

bxparks avatar bxparks commented on June 18, 2024 2

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.

bxparks avatar bxparks commented on June 18, 2024

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.

T-vK avatar T-vK commented on June 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.