Arduino 2560中的多维数组

时间:2016-03-31 23:36:37

标签: c++ multidimensional-array arduino

当我多次调用下面的函数时,会发生一些奇怪的事情。有人能帮帮我吗?

void fillCommandsArray( String commandName, String commandValue, String commandDelay ) {
  String commandsIndex[9] = { "j0", "j1", "j2", "j3", "g", "er", "ef", "el", "eb" };
  // Index of command name
  int index;
  // Finding the index of command name
  for( int i=0; i<9; i++ ) {
    if( commandName ==  commandsIndex[i] ) {
      index = i;
      break;
    }
  }
  // Fill the command name
  commands[index][0] = 1;
  // Fill the command value
  commands[index][1] = commandValue.toInt();
  // fill the command delay
  commands[index][2] = commandDelay.toInt();
}

参数是这样的:

fillCommandArray("er", "200", "2");

commands数组是这样的:

// Array for storing commands
int commands[9][3] = {
  { 0, 0, 0 },
  { 0, 0, 0 },
  { 0, 0, 0 },
  { 0, 0, 0 },
  { 0, 0, 0 },
  { 0, 0, 0 },
  { 0, 0, 0 },
  { 0, 0, 0 },
  { 0, 0, 0 }
};

当我多次调用该函数时,每次都会变成这样的数组:

第一到第四次:

0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
1 200 2000
0 0 0
1 200 2000
0 0 0

第五次:

7 0 0
0 0 0
0 0 0
0 0 0
0 0 0
1 200 2000
0 0 0
1 200 2000
0 0 0

第六次:

0 5 7
0 0 0
0 0 0
0 0 0
0 0 0
1 200 2000
0 0 0
1 200 2000
0 0 0

第七次:

0 0 5
7 0 0
0 0 0
0 0 0
0 0 0
1 200 2000
0 0 0
1 200 2000
0 0 0

继续...... 数字5和7将自动转移到数组的其他索引。 我知道ercommandsIndex的第5个索引,el是第7个。 我只是不知道这是怎么回事。这是硬件问题吗?这可能是硬件问题吗?

0 个答案:

没有答案