我正在尝试使用neoPixel和atm 8 LED灯条(之后会更长)来闪烁颜色。我要做的是给出一个像素信息列表并循环遍历列表并将灯光闪烁为“脚本数组”。说。
这是我到目前为止所做的代码:
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
int array[2][8][3] = {
{{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40}},
{{50, 90, 200}, {50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200}}
}; // flashing two colors on all leds
}
void loop() {
fromArray(50);
}
void fromArray(uint8_t wait){
for(int i=0; i<2; i++){
for (int j=0; j<8; j++){
strip.setPixelColor(j, strip.Color(array[i][j][0],array[i][j][1],array[i][j][2]))
}
strip.show();
delay(wait)
}
}
当我检查此代码时,我从第'array' was not declared in this scope
行收到错误strip.setPixelColor(j, strip.Color(array[i][j][0],array[i][j][1],array[i][j][2]))
。
答案 0 :(得分:0)
您的array
变量在setup
函数内声明,仅在此函数中可用。您只需将array
的声明移到全局范围内(setup
函数之外。
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);
int array[2][8][3] = {
{{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40}},
{{50, 90, 200}, {50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200}}
}; // flashing two colors on all leds
void setup() {
strip.begin();
strip.show();
}
void loop() {
fromArray(50);
}
void fromArray(uint8_t wait){
for(int i=0; i<2; i++){
for (int j=0; j<8; j++){
strip.setPixelColor(j, strip.Color(array[i][j][0],array[i][j][1],array[i][j][2]));
}
strip.show();
delay(wait);
}
}
您在我的fromArray
函数中遗漏了一些分号。我已在我的版本中添加了这些分号。
答案 1 :(得分:0)
您收到此错误的原因是您的setup()
函数中声明了数组,并且其余代码不可见。
你应该将它移到顶部。
int array[2][8][3] = {
{{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40},{120, 100, 40}},
{{50, 90, 200}, {50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200},{50, 90, 200}}
}; // flashing two colors on all leds
void setup() {
strip.begin();
strip.show();
}
void loop() {
fromArray(50);
}