当我多次调用下面的函数时,会发生一些奇怪的事情。有人能帮帮我吗?
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将自动转移到数组的其他索引。
我知道er
是commandsIndex
的第5个索引,el
是第7个。
我只是不知道这是怎么回事。这是硬件问题吗?这可能是硬件问题吗?