Arduino代码错误,用户输入的LED灯闪烁。

问题描述 投票:0回答:1

我被一些编译时的错误卡住了,没有得到解决的办法。

这是我做的代码。

void setup() {
 Serial.begin(9600);
 pinMode(13,OUTPUT);
}

void loop() {
 Serial.println("How many times you wanna blink the LED?");
 String myString;

 while(myString.equals("")) {
 myString = Serial.readString();
 }

 long int mystring;
 mystring = myString.toInt();
 Serial.print("Okay! the LED will blink ");
 Serial.println(myString);
 Serial.print(" times.");

 Serial.println("In how much time you want the LED to blink once? Please tell the time in milliseconds.");
 String mystr;

 while(mystr.equals("")) {
 mystr = Serial.readString();
 }
 long int myint;
 myint = mystr.toInt();
 Serial.print("Okay we will blink the LED in ");
 Serial.println(myint);
 Serial.print(" milliseconds once.");

 Serial.println("See the Show!!");
 int ms;
 ms = myint / 2;

 while(int i = 0; i < mystring; i++) {
 digitalWrite(13,HIGH);
 delay(ms);
 digitalWrite(13,LOW);
 delay(ms);
}
}

而这是我一次又一次得到的错误。

Arduino。1.8.10 (Windows 8.1), 板: "ArduinoGenuino Uno"

D:ANSH new/ArduinoBlink_LED_user_Input_TimesBlink_LED_user_Input_Times.inio: 在函数'void loop()'中。

Blink_LED_user_Input_Times:36:17: error: expected ')' before ';' token.

while(int i = 0; i < mystring; i++) {

             ^

Blink_LED_user_Input_Times:36:19: error: 'i' was not declared in this scope.

while(int i = 0; i < mystring; i++) {

               ^

在';'前加上退出状态1预期')'。

如果在File -> Preferences中启用 "Show verbose output during compilation "选项,该报告将有更多信息。

c++ compiler-errors arduino arduino-uno
1个回答
0
投票

你只能有一个条件,在一个 while

你的语法看起来像你想做一个 for 循环。

for (int i = 0; i < mystring; i++) { … }
© www.soinside.com 2019 - 2024. All rights reserved.