Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

One way to provide Arduino input parameters of any size without creating a struct is to use an array. For example, if you need to input a series of integers, you could create an integer array and pass it to a function.

Here's an example:

void myFunction(int *myArray, int arraySize) {
  for(int i=0; i<arraySize; i++) {
    Serial.println(myArray[i]);
  }
}

void setup() {
  Serial.begin(9600);

  int myArray[] = {1, 2, 3, 4, 5};
  int arraySize = sizeof(myArray)/sizeof(myArray[0]);

  myFunction(myArray, arraySize);
}

void loop() {
  //do nothing
}

In this example, we create an integer array called myArray with 5 integer values. We also calculate the array size by dividing the size of the array by the size of the first element.

We then pass myArray and arraySize to the myFunction function. Inside the function, we use a for loop to print out each element of the array using the Serial.println function.

By using an array, we can input any number of parameters without having to define a struct or hardcoding each parameter individually.