I am relatively new to c++ and programming for microcontrollers, but I have a few projects under my belt. I am currently trying to add some functionality to a working sketch by adding a library with some additional button processing capability. (SmartButton library by Marcin Borowicz on Github). When I try to compile one of the example sketches, it throws an error that seems to come from one of the .h files. I'm not a strong enough coder to figure out how to fix the error in his code (or even be sure it is really an error.)
Below is a portion of the compiler error message:
In file included from C:\Users\John\Documents\Arduino\libraries\SmartButton-master\src/SmartButton.h:4,
from C:\Users\John\AppData\Local\Temp\arduino_modified_sketch_243756\SmartButtonMulti.ino:3:
C:\Users\John\Documents\Arduino\libraries\SmartButton-master\src/SmartButtonDefs.h:17:39: error: invalid conversion from 'int (*)(uint32_t)' {aka 'int (*)(long unsigned int)'} to 'bool (*)(int)' [-fpermissive]
17 | constexpr bool (*getGpioState)(int) = digitalRead; //original version
| ^~~~~~~~~~~
| |
| int (*)(uint32_t) {aka int (*)(long unsigned int)}
Using library SmartButton-master at version 0.3.0 in folder: C:\Users\John\Documents\Arduino\libraries\SmartButton-master
exit status 1
Error compiling for board Adafruit Feather M0.
As you can see, I'm programming for an Adafruit Feather M0.
OK, I have moved it to the "Programming Questions" board as requested.
For future reference, if anyone needs a topic moved, please click the "Report to moderator" link and request it to be moved. It seems a little bit inappropriate maybe to "report" it, but it's just an effective way to communicate with the moderators. There's no automated forum system that will put you on the "naughty list" for having a report. I happened to be subscribed to notifications for this topic because I'm interested in the subject matter, but there's not guarantees the moderators will always see a reply on a topic.
The library was built for a different board than you are using, so the digitalWrite function has a different signature than what the function pointer is being declared as.
Fortunately, C++ has some handy features to avoid needed to guess the exact type of the function pointer. Replace the error line with this
constexpr auto getGpioState = digitalRead;
** **auto** **
, when used in an assignment declaration like this, basically says "make this variable whatever type is on the right-hand side of the equals sign".
PERT, thanks for moving the post and for the tip on getting moderator attention.
Jiggy-Ninja, thanks for the suggestion. That correction allowed the code to compile so now I can go on my merry way, making errors and trying to figure out how to fix them. (Learning)