简体   繁体   English

Arduino 语句错误。 ';' 前应为 ')' 令牌。 如何解决这个问题?

[英]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.

相关问题 arduino 错误:* 令牌之前的预期初始化程序 - arduino error: expected initializer before * token 语句错误:“在 &#39;,&#39; 标记之前应为 &#39;)&#39; - Error with a statement: "expected ')' before ',' token 编译器错误消息错误:&#39;*&#39;标记之前的预期&#39;)&#39;。 我的构造函数出错 - Compiler error message error:expected ')' before '*' token. Error with my constructor 如何在C ++中修复“错误:&#39;)&#39;标记之前的预期主表达式”? - How to fix “error: expected primary -expression before ')' token” in c++? 如何修复“错误:','标记之前的预期主表达式” - How to fix "error:expected primary-expression before ‘,’ token" 我为什么会收到“错误:&#39;&lt;&lt;&#39;标记之前的预期主表达式。” - Why am I getting “Error: expected primary-expression before '<<' token.” 错误:预期的构造函数,析构函数或&#39;(&#39;标记之前的类型转换。即使我有构造函数? - error: expected constructor, destructor, or type conversion before ‘(’ token. Even though I have a constructor? 错误:“]”标记之前的预期主表达式。 需要帮助 function 定义和调用 - Error: expected primary-expression before ']' token. Need assitance with function definition and calling 错误。 C ++。 &#39;)&#39;令牌之前的预期主要表达式 - Error. C++. Expected primary-expression before ')' token 在“;”之前修复预期的不合格ID 令牌错误 - Fix Expected Unqualified id before ';' token error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM