感谢您的关注!
背景
我正在构建一个四轴飞行器,每个手臂上都放置了一条 RGB 可寻址 LED。我正在使用 Arduino 来驱动灯,而 Arduino 代码是 C++,一种我不太了解的语言。
这是我发布的第一个 StackOverflow 问题,涉及我之前使用此代码时遇到的问题。它为您提供了有关我到底想要做什么的更多背景信息(如果您有兴趣)。
问题
由于我的第一个问题的答案,我现在已经正确地编写了数组“gpsHoldArr” ,但是我无法访问它的值。
在下面的代码中,我调用toggleLights(gpsHoldArr[x][y])
并传入gpsHoldArr
. 子阵列应该是指向给定 LED 灯条 ( [x]
) 和给定步骤 ( [y]
) 的结果。
toggleLights
然后应该迭代它传递的数组并将每个 LED 的值(从 1 到 6 的某个数字)和 LED 的红色、绿色和蓝色值发送到控制台。
不幸的是,当我运行下面的代码时,我收到了这个错误:
cannot convert int(*)[3] to int* for argument 1 to 'void toggleLights(int*)'
任何帮助将不胜感激。
这是当前代码:
//4 arms, 6 steps, 6 leds
int gpsHoldArr[4][6][6][3] = {
{
{{255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}}
},
{
{{255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}}
},
{
{{255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}}
},
{
{{255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {0,0,0}},
{{255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}, {255,0,0}}
}
};
toggleLights(gpsHoldArr[0][0]); //Toggles lights on strip #1, step #1
toggleLights(gpsHoldArr[1][0]); //Toggles lights on strip #2, step #1
toggleLights(gpsHoldArr[2][0]); //Toggles lights on strip #3, step #1
toggleLights(gpsHoldArr[3][0]); //Toggles lights on strip #4, step #1
void toggleLights(int lights[]){
for(int i = 0; i <= 6; ++i)
{
set_color_led(i, lights[i], lights[i], lights[i]);
}
}
void set_color_led(int led, int r, int g, int b){
Serial.println(led); //Which LED (or "pixel") is it?
Serial.println(r); //What is the red value?
Serial.println(g); //What is the green value?
Serial.println(b); //What is the blue value?
}