bxparks / AceButton

An adjustable, compact, event-driven button library for Arduino that debounces and dispatches events to a user-defined event handler.
MIT License
385 stars 37 forks source link

GPIO pin 0 cannot be used? #40

Closed henk65 closed 4 years ago

henk65 commented 4 years ago

Trying to use AceButton on pin 0 gives me this error:

exit status 1 call of overloaded 'AceButton(int)' is ambiguous

All other pins are okay, except pin 0. What can be done about this?

bxparks commented 4 years ago

Try AceButton((uint8_t) 0).

This is caused by 2 overloaded constructors:

C++ maps a 0 to either an int or a void*. I'm not really sure how to get around that. Open to suggestions.

bxparks commented 4 years ago

This stackoverlow suggests a way to disambiguate (https://stackoverflow.com/questions/4610503/how-to-resolve-ambiguity-of-call-to-overloaded-function-with-literal-0-and-point) but it's kinda ugly. Not sure I want to introduce that kind of clutter into the code.

henk65 commented 4 years ago

Okay, it's working now. That's not the way I usually do it, but it did the trick for me and I'm fine with it.

Shall I close this issue now, or do you want to leave it open for suggestions from others? You can close it if you want to, I'm okay with that...

bxparks commented 4 years ago

Added notes in the README.md.

bxparks commented 4 years ago

It occurred to me that an alternative, perhaps cleaner, solution is to use a const:

const uint8_t PIN = 0;
AceButton button(PIN);