0

I'm currently working on a 8x8 LED matrix program, and came across code which uses a 8x10 matrix engine.

EDIT 'A' and 'R' are defined strings given:

#define A     {B00000000,B00111100,B01000010,B01000010,B01000010,B01111110,B01000010,B01000010,B01000010,B00000000}

and #define R {B00000000,B00111100,B01000010,B01000010,B01000010,B01111100,B01000100,B01000010,B01000010,B00000000}

I'm currently attempting to change this line (8x10 matrix array)

const int numPatterns = 16;//this is the number of patterns you want to display
byte patterns[numPatterns][10]={A,R,A,R,A,R,A,R,A,R,A,R};// the patterns order

To this:

const int numPatterns = 16;//this is the number of patterns you want to display
byte patterns[numPatterns][8]={A,R,A,R,A,R,A,R,A,R};// the patterns order

However, it proceeds to give me an error, I've tried myself to understand the concepts of 2D arrays in other languages, except from my basic experience in this IDE, it seems to dislike any real changes to 2D arrays.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user3739406
  • 254
  • 1
  • 3
  • 16

1 Answers1

1

This works:

#define A {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
#define R {21, 22, 23, 24, 25, 26, 27, 28, 29, 30}

const int numPatterns = 16;//this is the number of patterns you want to display
byte patterns[numPatterns][10]={A,R,A,R,A,R,A,R,A,R,A,R};// the patterns order

Changing "10" to "8" causes the error message.

This also works:

#define A {1, 2, 3, 4, 5, 6, 7, 8}
#define R {21, 22, 23, 24, 25, 26, 27, 28}

const int numPatterns = 16;//this is the number of patterns you want to display
byte patterns[numPatterns][8]={A,R,A,R,A,R,A,R,A,R,A,R};// the patterns order

The number of elements in each of A and R must fit in the second dimension in the array declaration. To get down to 8 by 8 you will also have to limit the total number of "A" or "R" elements in patterns to no more than 8.

Patricia Shanahan
  • 25,849
  • 4
  • 38
  • 75
  • Sorry forgot to write what 'A' and 'R' were, I doubt this fixes my problem because you are redefining 'A' and 'R' (My bad for not posting their definitions) – user3739406 Jun 19 '14 at 02:54
  • Patricia nailed it on the head, your A and R have too many elements. The "8" part of patterns[numPatterns][8] says that A and R must have 8 elements, and the code you found defines 10. – Ben Jun 19 '14 at 02:59
  • @user3739406 You cannot have as many elements in an 8 element array as you can in a 10 element array. You either need to keep the array size, or redefine A and R to fit. – Patricia Shanahan Jun 19 '14 at 03:24