For my model railroad I wrote a processing sketch which has several objects in an array list. When the program is running I can add and remove objects and toggle states of things etc etc.
Now I am writing the arduino side of the story. At the moment I am writing my Switch class. A switch object in the program is nothing more than a class to control a servo motor.
It may be that the servo is driven by an I2C servo driver board or that I use an I/O of the arduino itself. So when I make a new Switch I give 3 parameters to the constructor; the ID, the I/O pin and whether that pin is of the I2C driver or not.
As my modeltrack will contain several arduino nano's I want one universal program which lets me configure an arduino via the serial bus.
In Processing I had the convenience of dynamic sized array lists. But now.....
What I want to ask is the following. When the program is running, I'd like to be able to create a new switch object by sending instructions through the serial bus. And the arduino also needs to make switch objects with information collected from it's internal EEPROM after start up. I believe that this is all is not very problematic...
... but than... The arduino can receive an instruction via a RS485 network, telling him that switch 5 has to move to state true which will be 'curved'.
I believe that I need to construct a for-loop for this in which I call a switchArray_.getID() function of every switch untill I have a match on ID. And than call I can call switchArray*.setState(true) function to set the switch. Atleast this is what I want but...*_
This all means that I need somekind of a dynamic array to which I can add and perhaps also remove switches.
My first questions to you:
Is this possible and how would such a loop look like?
If it would not be possible, I could ofcourse create a fixed ammount Switch objects. Lets say I create 20 separate switches. Than I can build an array with a fixed size. And use setter functions from with data from EEPROM or serial bus
Last question:
what would the most practical solution be