我对Arduino和C++相对较新,我被困在这个错误上。我正在尝试让 LED 同时划过矩阵。
我收到的错误消息是
"退出状态 1.预期在";"标记之前为"(">
任何帮助都会很棒。
#define NUM_LEDS 64
#define DATA_PIN 3
CRGB leds[NUM_LEDS];
int count1 = 0;
int count2 = 0;
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
for ((count1 = 0; count1 <= 15; count1++) and (count2 = 31; count2 >= 16; count2--)) {
leds[count1] = CRGB::Blue;
leds[count2] = CRGB::Blue;
FastLED.show();
delay(100);
leds[count1] = CRGB::Black;
leds[count2] = CRGB::Black;
}
}
您的for
循环不起作用。
for
循环为:for
(initial
;test
;update
(
这三个部分之间都带有"and",这是无效的语法。
for ((count1 = 0; count1 <= 15; count1++) and (count2 = 31; count2 >= 16; count2--)) {
<- 无效!
你可以做的是:
for (count1 = 0, count2 = 31; count1 <= 15 && count2 >= 16; count1++, count2--)
您提供的代码中存在许多问题(例如没有定义变量 - 但是,我假设您只是没有提供所有相关代码(。主要问题是你的"for loop"语法,你可能希望它看起来像这样:
#define NUM_LEDS 64
#define DATA_PIN 3
CRGB leds[NUM_LEDS];
int count1 = 0;
int count2 = 0;
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop() {
for (count1 = 0; count1 <= 15; count1++){
for (count2 = 31; count2 >= 16; count2--) {
leds[count1] = CRGB::Blue;
leds[count2] = CRGB::Blue;
FastLED.show();
delay(100);
leds[count1] = CRGB::Black;
leds[count2] = CRGB::Black;
}
}
}