[英]Arduino for statement error. Expected ')' before ';' token. How to fix this?
我對 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
)
這三個部分都有兩次,它們之間有一個“和”,這是無效的語法。
for ((count1 = 0; count1 <= 15; count1++) and (count2 = 31; count2 >= 16; count2--)) {
<- 無效!
你可以做的是:
for (count1 = 0, count2 = 31; count1 <= 15 && count2 >= 16; count1++, count2--)
您提供的代碼中存在許多問題(例如未定義變量 - 但是,我假設您只是沒有提供所有相關代碼)。 主要問題是您的“for 循環”語法,您可能希望如下所示:
#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;
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.