Using arrays with multiple inputs? - is this good idea?

Hi boys, I make one project, which have a some inputs (4-8). I´m newbie in Arduino, but I have practice with asm, etc. So, I thinking about solution of this program. I need make a functions, which will be calculating time of press, etc. I thinking about use of arrays for clean code.

For examle : I want use

int inputTime[] = {0, 0, 0, 0}; // time of each input (0-3)

instead : int inputTime1 = 0 int InputTime2 = 0 ...

I can make another variable or definition - maxInputs, which will hold number of inputs and my functions will be read of this. When I call inputsUpdate() for example, it read maxInputs and with for cycle it read every input state and place this to my arrays.

Is this good idea? I found some libraries for input debounce, etc... but I want study and use functions and arrays and make my own solution without libraries. I think this solution is little similar as class and instancies - is it right?


If you do large amounts of work on the data, an array would seem far more efficient as you can use loops to remove the repetitive code. Once you can use arrays efficiently and if your design changes, you could possibly add/remove a inputs with very little additional work; As already have the code there, you just need to increase/decrease the number of iterations on your loops ( maybe with a define or constant ).

As for the non-array approach. Looped algorithms are not as fast as their linear counterparts, however the amount of redundant code may be a burden if you are running out of flash.

Classes are a different story, and not something you need if you do not understand them yet. You can create instances of classes, just like standard types like 'int', and 'char'. Libraries become useful when you have some code that is specific to a task. The class helps by allowing you to keep 'like' things together, such as functions that work on the task, variables that hold states of the task, and so on.