How to store bulk data and/or point to array?
Hi,
My first post - I look forward to learning a lot here.
I am getting back into C programming after about 20+ years away from it. This is for an embedded project running on a microcontroller.
To explain what I am doing, I have a 3x3 array of lights, and I want to take a key press from the user and each time the key is pressed, I cycle to the next in a series of patterns which get displayed on the array of lights.
The patterns are made up of a series of frames. Each frame is 9 elements (basically 1 or 0 depending on if the light will be on), and there may be anywhere from a single frame to, say, 20 frames in one pattern. I am hoping to have maybe 100 patterns in total for the final project.
Right now, I am just storing each pattern in an array and the first digit of the array denotes how many frames are contained in that array.
Code:
char P1[] = {3, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
char P2[] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
char P3[] = {2, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
char P4[] = {1, 0, 1, 0, 1, 0, 1, 0, 1, 0};
I have a function which runs in the background and constantly updates the display. So when the user presses a key, I want to switch from P1 to P2. I am trying to avoid a giant switch statement in my function that updates the display. So what I would like to do is have a global variable that denotes the memory location which holds the pattern, and then the function would just start reading it and display the data.
My questions are, does storing my data in arrays make sense? I am very much a noob with C, so I am not sure if there is some "bulk data" format that I can just put a bunch of data in my program more efficiently than storing it in arrays?
And what syntax would I use to denote the memory address of the first element in an array? I realize this is what pointers are, but I am getting confused reading tutorials when they say that arrays are essentially pointers right off the bat = but I can't pass the address of, for example, the P1[] array just by writing P1, or maybe I can? I get compile errors when I try.
Any information is greatly appreciated!