如何在Arduino编程中访问数组中的数据值?
该计划如下:
int myArraylt[24]= {3530,1580,3880,2780,4040,11260,7935,6655,2100,5100,1450,2200,2200,5900,6180,4230,2405,3560,4535,12635,12085,3500,930,3430};
int myArraygt[24]= {0,0,0,0,0,0,6320,5496.9,5948,4124.1,3848.4,3573,3022.2,3297.6,3298.2,3573,4123.2,0,0,0,0,0,0};
void setup() {
for (int i=1;i=1;i++)
if (myArraygt(i)>myArraylt(i))
println( SSystem is on MG);
else
println( SSystem is on GRID);
}
void loop() {
// put your main code here, to run repeatedly:
}
答案 0 :(得分:0)
在你的代码中几乎没有错误
0
开始,但是在for循环中,您是从1
i=1
它仅针对数组索引运行循环1
array[i]
格式(不是数组(i))Serial.println()
进行打印,而不仅仅是println()要访问数组值,代码应如下
int myArraylt[24]= {3530,1580,3880,2780,4040,11260,7935,6655,2100,5100,1450,2200,2200,5900,6180,4230,2405,3560,4535,12635,12085,3500,930,3430};
int myArraygt[24]= {0,0,0,0,0,0,6320,5496.9,5948,4124.1,3848.4,3573,3022.2,3297.6,3298.2,3573,4123.2,0,0,0,0,0,0};
void setup() {
for (int i=0;i<24;i++)
if (myArraygt[i]>myArraylt[i])
Serial.println( SSystem is on MG);
else
Serial.println( SSystem is on GRID);
}
void loop() {
// put your main code here, to run repeatedly:
}
如果你想打印SSystem在MG上,SSystem在屏幕上的GRID上,那么它必须放在双引号内Serial.println( "SSystem is on MG");
和Serial.println( "SSystem is on GRID");