用户输入时 LED 闪烁的 Arduino 代码错误

Arduino Code Error for blinking LED with user Input

我遇到了一些编译时错误,没有得到解决方案。

这是我编写的代码:

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), Board: "Arduino/Genuino Uno"

D:\ANSH new\Arduino\Blink_LED_user_Input_Times\Blink_LED_user_Input_Times.ino: In function '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++) {

               ^

exit status 1 expected ')' before ';' token

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.

一个条件只能有一个 while loop

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

for (int i = 0; i < mystring; i++) { … }