2D阵列的初始化程序太多(Arduino IDE)

时间:2014-06-19 01:43:23

标签: arrays matrix arduino initializer

我目前正在开发8x8 LED矩阵程序,并且遇到了使用8x10矩阵引擎的代码。

编辑' A'和' R'是给定的字符串:

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

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

我目前正在尝试更改此行(8x10矩阵数组)

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

对此:

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

然而,它继续给我一个错误,我已经尝试了解其他语言中的2D数组的概念,除了我在这个IDE中的基本经验,它似乎不喜欢2D数组的任何真正的改变。

1 个答案:

答案 0 :(得分:1)

这有效:

#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

改变" 10"至" 8"导致错误消息。

这也有效:

#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

A和R中每个元素的数量必须符合数组声明中的第二个维度。要达到8乘8,你还必须限制" A"或" R"模式中的元素不超过8个。