Arrays are confusing...

Hey everyone!

I cant seem to understand how they work, how to create them, and how to access them...

If someone can explain how they work, and for bonus points how to use them to initialize a keypad matrix, that'd be awesome.

I've read countless explanations, but can't seem to get it.

Thanks!

Why not tell us what is confusing so we can narrow in on your problem.

There really is a huge wealth of information on the Internet on the topic.

I need to know more about the syntax, so I am more fluent when it comes to using them.

Can you follow this? http://www.thebox.myzen.co.uk/Tutorial/Arrays.html

Another one for you to consider:

http://www.thegeekstuff.com/2011/12/c-arrays/

This is how I remembered them in school. 1D: Array[ houses ] = { 1, 2, 3}; 2D: Array[ street ][ houses ] = { { 1, 2,3}, {4,5,6} }; 3D: Array[ block ][ street ][ houses] = { { {1,2,3}, {4,5,6} }, { {7,8,9}, {10,11,12} }, { {13,14,15}, {16,17,18} } } Now to call them you put in the address. 1D: Array[0] = 1 2D: Array[1][2] = 6 3D: Array[2][0][1] = 14

Hope this helps.

would this work?

I'm trying to have a 4x4 pad and one extra for another function:

//-----------buttonpad---------- const rows = 4; const columns = 5; char keys[rows][cols] = { {'1a','1b','1c','1d','su'}, {'2a','2b','2c','2d','blank'}, {'3a','3b','3c','3d','blank'}, {'4a','4b','4c','4d','blank'} }; byte rowPins[rows] = {5, 4, 3, 2}; byte colPins[cols] = {12, 11, 10, 9, 8}; Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols ); //------------------------------

Single quotes is for an ascii character like the letter A or the number 5. To us they look correct but the code sees 65 and 53. If you want actual words (S/strings) then you need to use double quotes "just like this".

Calling a string from an array is easy but you should be familiar with pointers ( * ) Ex. char * myWords[3] = {"Hello", "World!", "Pie"}; Serial.println( myWords[0]); // shows Hello Serial.println( myWords[2]); // shows Pie

So it's characters and strings you want help with.

It might be useful to know that in C++ (which Arduino uses), a string is stored as an array of characters. I'd give more info, but I don't feel like going down that rabbit hole just now...

odometer: C++ (which Arduino uses)

wait, I thought Arduino uses C? (plain old C, not ++)

Quote from the reference:

The Arduino language is based on C/C++.

As it supports objects it can't be C alone ;)