[英]Arduino for statement error. Expected ')' before ';' token. How to fix this?
I am relatively new to Arduino and C++ and I am stuck on this error.我对 Arduino 和 C++ 比较陌生,我一直被这个错误所困扰。 I am trying to have LEDs streak across a matrix at the same time.
我试图让 LED 同时在矩阵上出现条纹。
The error message I receive is我收到的错误消息是
"exit status 1. expected ')' before ';'
“退出状态 1。在 ';' 之前应为 ')' token"
令牌”
Any help would be great.任何帮助都会很棒。
#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;
}
}
Your for
loop doesn't work.您的
for
循环不起作用。
A for
loop is: for
( initial
; test
; update
) for
循环是: for
( initial
; test
; update
)
You have all of those three parts twice with an "and" between them, that is invalid syntax.这三个部分都有两次,它们之间有一个“和”,这是无效的语法。
for ((count1 = 0; count1 <= 15; count1++) and (count2 = 31; count2 >= 16; count2--)) {
<- Invalid! for ((count1 = 0; count1 <= 15; count1++) and (count2 = 31; count2 >= 16; count2--)) {
<- 无效!
What you can do is this:你可以做的是:
for (count1 = 0, count2 = 31; count1 <= 15 && count2 >= 16; count1++, count2--)
There are a number of problems in your provided code (like not defining your variables - I'm assuming, however, that you have merely not provided all relevant code).您提供的代码中存在许多问题(例如未定义变量 - 但是,我假设您只是没有提供所有相关代码)。 The main issue is your "for loop" syntax, which you may want to look like this:
主要问题是您的“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.