(deleted)
Please post your complete sketch and a link to the library being used
It may be possible to create an array of button objects
Well, you could declare the buttons in an array[]... e.g button[n]?...
Then iterate through a loop, calling the required function() with the appropriate values for each call (fir each button[])
This could well help you optimise other parts of your code, and will shorten it significantly - especially with 12 buttons.
There are previous posts on here that discuss buttons in an array
The first thing to do is to replace all variables like button1, button2 etc. with an array:
ezButton buttons[] = { 2, 3, 4}; // 2, 3, 4 are example pin numbers
Edit: changed "const int" to "ezButton".
Then you can use code like this to set properties:
for (auto button : buttons) {
button.setDebounceTime(50);
}
Erik_Baas:
The first thing to do is to replace all variables like button1, button2 etc. with an array:const int buttons[] = { 2, 3, 4}; // 2, 3, 4 are example pin numbers
Then you can use code like this to set properties:
for (auto button : buttons) {
button.setDebounceTime(50);
}
Since when have const ints a method setDebounceTime() ?
Since OP did not post their complete code I didn't know the datatype, so I used an integer array as an example. Remark added.
Erik_Baas:
Since OP did not post their complete code I didn't know the datatype, so I used an integer array as an example.
IMHO that is more misleading than helping.
Let's wait for @zt_ 's response; I will delete my replies if necessary. OK?
You could just change the const int type to some unspecified 'Button'.
zt_:
I'm using the ezbutton library
Mr. Google tells me the name of the class is ezButton.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.