Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a huge number of arrays, each with a series of numbers each referring to an LED on a strip. I want to be able to address each one by a number, so the logical solution to that for me was to make the whole thing into an array. Can that be done, or is there a better work around that can be implemented?

share|improve this question
    
Yes t is possible: you should take a look at cplusplus.com/doc/tutorial/arrays and search for "multidimensional arrays" there. – jfpoilpret May 6 '16 at 9:25
    
My word, my mind is blown. Thanks for that @jfpoilpret. I'll see what I can do with that. – Matthew Inglis May 6 '16 at 9:30
up vote 2 down vote accepted

Yes you can have arrays inside arrays.

The array would be declared as:

int arrayName [ x ][ y ];

where x is the number of rows and y is the number of columns.

The example below declares and initializes a 2D array with 3 rows and 10 columns:

int myArray[3][10] = { { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 },
                       { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 },
                       { 21, 22, 23, 24, 25, 26, 27, 28, 29, 30 } };

To access the value of 27 (and save it into myValue):

myValue = myArray[2][6];
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.