Hello,
I'm new to Arduino and haven't used C++ in 20 years (lots of python and web languages since).
I'm trying to create arrays of various hardware objects and believe I'm hitting some syntax issues that I'm hoping someone can point me in the right direction.
I'm using this button library: Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
If I create an array of buttons above the setup() function like this it works fine:
Button betButtons[] = {
Button(2,BUTTON_PULLUP_INTERNAL, true, 50),
Button(3,BUTTON_PULLUP_INTERNAL, true, 50)
}
That seems inefficient so I want to use a for() loop to create these so I try:
Button betButtons[10]; //define empty array of type:Button
//Load the Array
for(int i=0;i<10;i++) {
betButtons = Button(i+2,BUTTON_PULLUP_INTERNAL, true, 50);
}
Logic seems right but it errors saying no matching function for call to 'Button::Button()' on the Button betButtons[10] line.
I've been reading for the past hour on this and it seems there are a couple issues:
1. You can't do for loops outside the setup() and loop() or some other function so I try to define array at the top and put for loop inside setup() function but no dice.
2. Arrays / Pointers C++ stuff that I don't know about
This seems like super-basic functionality but I have not been able to find an example of how to build arrays of hardware class elements.
At the end of the day I want to be able to access buttons (or other things for that matter) using:
dosomething(betButtons[2]);
Any help would be appreciated or links to the concept I'm missing here.
Thanks,
Andy