int data1[]{0,198,227,243,219,207,198,0};//number 1
int data2[]{0,195,102,60,60,102,195,0};//number
int datas[]{"data1","data2","data1","data2","data1","data2","data1","data2"};
I can use the arrays data1 and data2 above but wonder if I can choose them from another array so a loop would give me the contents of data1 on the first pass and the contents of data 2 on the second.
so that I can use something like
for (int s=0;s<8;s=s++)
{
int dataa=datas[s];
for (int t=0;t<8;t=t++)
{
SetRow(color,t,dataa);
}
}
compiling int datas[] tells me it should be a const char but changing it to const char datas[] tells me too many initializers for 'const char []'
is there a way of doing this?
I don't think that is my solution
I'm trying to address an 8 x 8 bicolour matrix.
I am using Brohogans ISR interupt routine (turns red and yellow off and on sequentially) so I call a routine SetRow that does the lc.setRow.
I have written a routine that has rows of instructions that are all similar
i.e.
turn red on, do a loop of 8, send the 8 bits of information
turn green on do a loop of 8 send the 8 bits of information
etc
I just wondered if I could put the differences in an array and do the program once with different data each time. I am only doing it to learn the language.
A 2D array would mean building the array with the same info each time
i.e.
array[8][8]{{0,1,1,0,0,0,1,1}//0 is red 1 is green
,{ eight bit info1, eight bit info2, eight bit info1,eight bit info1 etc}};
eight bit info 1[]{126,123,12,134,124,212,123,212};
eight bit info 2[]{112,110,123,145,123,154,112,12};
the second part of array 'array' needs to get the info from the two eight bit info arrays?
Can that be done?
int data1[] = {0,198,227,243,219,207,198,0}; //number 1
int data2[] = {0,195,102,60,60,102,195,0}; //number
int *datas[] = {data1, data2, data1, data2, data1, data2, data1, data2};
void setup() {
int i, j;
int *ptr;
Serial.begin(9600);
for (i = 0; i < 8; i++) {
ptr = datas[i]; // Pick the array wanted...
for (j = 0; j < 8; j++) {
Serial.print(*ptr++);
Serial.print(" ");
}
Serial.println();
}
}
void loop() {
// put your main code here, to run repeatedly:
}
The first use of the asterisk is to define an array of pointers, which are nothing more than memory addresses. Note that the pointer's data type must match the array type so the pointer arithmetic works correctly.
When the asterisk is used in a binary expression, like seen in the loops, it's what is called the indirection operator which is associated with pointers. The variable named ptr holds a number which is actually the address of another variable. This relationship can be seen below.
So if ptr is stored in memory at address 2294 and your array named data1[] is stored starting at address 2292, the indirection operator (*) says: "Go to ptr's memory address (2294) and fetch its contents (2292) and then go to that memory address and get your data (e.g., 5)." My code simply changes the 2292 memory address stored in ptr to the first element of each of your two arrays on each pass through the loops.
Correct. Suppose your array named data1[] resides at memory address 100 and data2[] at memory address 200. Therefore, data1[0] is at 100, data1[1] is at 102, data1[2] is at 104 and so on. With data2[], the relationship is: data2[0] is at 200, data2[1] is at 202, and so on. Therefore, the datas[] array looks like: datas[0] = 100, datas[1] = 200, datas[2] = 100 and so on.
Now look at the statement:
ptr = datas[i];
On the first pass through the i loop, ptr is assigned datas[0], or 100. The j loop then goes to that memory address, which is where data1[] is stored, and displays the 8 values found in the array.
On the next pass through the i loop, ptr would be changed to datas[1] (i.e., memory address 200) and point to the data2[] array and the j loop then displays its 8 values.
If you walk yourself through each pass of the loops, you should be able to figure out what's going on.
If you walk yourself through each pass of the loops, you should be able to figure out what's going on.
I have managed to get one row to light with the leds that I need to show on each row, it looks like I need to get the for statements worked out.
Thanks for the help.
I will update this thread when, (or if?) I get it to work.
Thanks econjack,
I have been able to put the display on all the leds and swop colours as well as the data.
I appreciate the sketch you have written and will analyse it to death.
Again thank you.