# Changing arrays

OK, so I have 3 arrays of 10 values. I wish to be able to change through these arrays with the press of a button, but I'm having trouble changing the arrays.

I have in my code, the variable "currarray", which is the current array. I also have 3 other arrays, array1[10], array2[10] and array3[10]

Somehow, I need to put any of those 3 arrays, into currarray?

For example, I tried:

byte currarray[] = array1[];

However, I get error messages.

I also tried byte currarray = array1;

Still didn't work.

A snippet of my code:

``````byte array1[10] = {36, 41, 43, 44, 46, 48, 49, 51, 53, 55};
byte array2[10] = {35, 47, 54, 55, 57, 59, 60, 61, 62, 64};
byte array3[10] = {48, 60, 62, 63, 65, 67, 69, 70, 72, 74};

if (currarray[] == array1[]){
currarray[] = array2[];
digitalWrite(18, HIGH);
digitalWrite(17, LOW);
digitalWrite(19, LOW);
}
if (currarray[] == array2[]){
currarray[] = array3[];
digitalWrite(19, HIGH);
digitalWrite(18, LOW);
digitalWrite(17, LOW);
}
if (currarray[] == array3[]){
currarray[] = array1[];
digitalWrite(19, LOW);
digitalWrite(18, LOW);
digitalWrite(17, HIGH);
}
}
``````

How would I go about doing this?

Regards

Make a multidimensional array of it

``````#define BUTTON_1  4

byte array[3][10] = {
{36, 41, 43, 44, 46, 48, 49, 51, 53, 55},
{35, 47, 54, 55, 57, 59, 60, 61, 62, 64},
{48, 60, 62, 63, 65, 67, 69, 70, 72, 74}
};

int arrayselector= 0;  // may also be called differently but meaningfull var names helps to understand code.

void setup()
{
Serial.begin(115200);
}

void loop()
{
{
arrayselector= (arrayselector+ 1) %3;  // changes from 0->1->2->0
}

Serial.println(array[arrayselector][4]);
delay(1000);
}
``````

The button just changes the arrayselector from 0->1->2->0

Thanks, that is exactly what I was wanting

Regards,
Dan

one way would have been to use a for loop.
e.g.

``````for (int i=0; i<10; i++) {
array1[i] = currarray[i];
}
``````

if you wanted to be able to switch between arrays u could make 3 different for loops and use switch case.
But i think you could use pointers to not to sure on how maybe somebody here knows

Use a pointer.

byte* currarray;
array1[10] = {1,2,3,...}
array2[10] = {11,12,13,...}

currarray = array1; //now currarray points to array1 and currarray[n] = array1[n]

....some code....

currarray = array2; //now currarray points to array2 and currarray[n] = array2[n]

Use a pointer.

byte* currarray;
byte array1[10] = {1,2,3,…}
byte array2[10] = {11,12,13,…}