I'm using two 8x8 flexible LED grids, and attempting to control the two individually (each on their own data pin).
I'm attempting to make it light up in various different patterns/animations using multidimensional arrays.
However, when passing a 2D array as a parameter in a function, it seems to lose most of it's data. I saw in another thread that sizeof
will not return the correct size because it's a pointer of the array. That's fine, I can pass the size as an additional parameter. The problem is the lack of the actual data.
For example, this is one of the arrays:
byte ROLLING_EYE[][64] = {
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 0, 0, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 0, 0, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 0, 1, 1, 0, 1, 1, // Forward
1, 1, 0, 1, 1, 0, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 1, 1, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 1, 1, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 1, 1, 1, 1, // Reverse
1, 1, 1, 1, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 1, 1, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 1, 1, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 0, 1, 1, 0, 1, 1, // Forward
1, 1, 0, 1, 1, 0, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 0, 0, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 0, 0, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 1, 1, 0, 0, 1, 1, // Reverse
1, 1, 0, 0, 1, 1, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
{
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
1, 1, 0, 0, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 0, 0, 1, 1, // Reverse
1, 1, 0, 0, 0, 0, 1, 1, // Forward
1, 1, 0, 0, 0, 0, 1, 1, // Reverse
1, 1, 1, 1, 1, 1, 1, 1, // Forward
1, 1, 1, 1, 1, 1, 1, 1, // Reverse
},
};
And then this is the code I'm currently using to read the array (no functionality because data isn't right)
void loop() {
if (random(1, 100) >= 80) {
rollEye(ROLLING_EYE, false);
}
}
void rollEye(byte data[][64], bool isRightEye) {
for(int i = 0; i < sizeof(data)-1;i++) {
Serial.print(F("Idx: "));
Serial.println(i);
for(int j = 0; j < sizeof(data[i]) - 1; j++) {
Serial.print(F("Idx2: "));
Serial.print(j);
Serial.print(F(" Val: "));
Serial.println(data[i][j]);
}
}
}
And this is what appears in the Serial Monitor:
Idx: 0
Idx2: 0 Val: 1
Idx2: 1 Val: 1
Idx2: 2 Val: 1
Idx2: 3 Val: 1
Idx2: 4 Val: 1
Idx2: 5 Val: 1
Idx2: 6 Val: 1
Idx2: 7 Val: 1
Idx2: 8 Val: 1
Idx2: 9 Val: 1
Idx2: 10 Val: 1
Idx2: 11 Val: 1
Idx2: 12 Val: 1
Idx2: 13 Val: 1
Idx2: 14 Val: 1
Idx2: 15 Val: 1
Idx2: 16 Val: 1
Idx2: 17 Val: 1
Idx2: 18 Val: 0
Idx2: 19 Val: 0
Idx2: 20 Val: 1
Idx2: 21 Val: 1
Idx2: 22 Val: 1
Idx2: 23 Val: 1
Idx2: 24 Val: 1
Idx2: 25 Val: 1
Idx2: 26 Val: 1
Idx2: 27 Val: 1
Idx2: 28 Val: 0
Idx2: 29 Val: 0
Idx2: 30 Val: 1
Idx2: 31 Val: 1
Idx2: 32 Val: 1
Idx2: 33 Val: 1
Idx2: 34 Val: 0
Idx2: 35 Val: 0
Idx2: 36 Val: 0
Idx2: 37 Val: 0
Idx2: 38 Val: 1
Idx2: 39 Val: 1
Idx2: 40 Val: 1
Idx2: 41 Val: 1
Idx2: 42 Val: 0
Idx2: 43 Val: 0
Idx2: 44 Val: 0
Idx2: 45 Val: 0
Idx2: 46 Val: 1
Idx2: 47 Val: 1
Idx2: 48 Val: 1
Idx2: 49 Val: 1
Idx2: 50 Val: 1
Idx2: 51 Val: 1
Idx2: 52 Val: 1
Idx2: 53 Val: 1
Idx2: 54 Val: 1
Idx2: 55 Val: 1
Idx2: 56 Val: 1
Idx2: 57 Val: 1
Idx2: 58 Val: 1
Idx2: 59 Val: 1
Idx2: 60 Val: 1
Idx2: 61 Val: 1
Idx2: 62 Val: 1
(and then it repeats each loop) As you can see, it's missing a lot of values that should exist.
Ideally, I want a single function that I can pass [array] of values to and then have that function control the lights on whichever 8x8 LED grid is selected. I'm also trying to work within the Arduino Uno's limitations. Any tips regarding how to keep it at a manageable project size while being able to add a variety of different animations would be greatly appreciated.