简体   繁体   English

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

[英]Arduino Code Error for blinking LED with user Input

I am stuck in some compile time error and not getting the solution for it.我陷入了一些编译时错误,没有得到解决方案。

This is the code I have made:这是我制作的代码:

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);
}
}

and this is the error I am getting again and again.这是我一次又一次遇到的错误。

Arduino: 1.8.10 (Windows 8.1), Board: "Arduino/Genuino Uno" Arduino:1.8.10(Windows 8.1),板:“Arduino/Genuino Uno”

D:\ANSH new\Arduino\Blink_LED_user_Input_Times\Blink_LED_user_Input_Times.ino: In function 'void loop()': D:\ANSH new\Arduino\Blink_LED_user_Input_Times\Blink_LED_user_Input_Times.ino:在 function 'void loop()' 中:

Blink_LED_user_Input_Times:36:17: error: expected ')' before ';' Blink_LED_user_Input_Times:36:17: 错误:在 ';' 之前预期 ')' token令牌

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

 ^

Blink_LED_user_Input_Times:36:19: error: 'i' was not declared in this scope Blink_LED_user_Input_Times:36:19: 错误: 'i' 未在此 scope 中声明

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

 ^

exit status 1 expected ')' before ';'退出状态 1 预期 ')' 在 ';' 之前token令牌

This report would have more information with "Show verbose output during compilation" option enabled in File -> Preferences.此报告将在文件 -> 首选项中启用“在编译期间显示详细 output”选项的更多信息。

You can have only one condition in a while loopwhile循环中只能有一个条件

Your syntax looks like you wanted to do a for loop:你的语法看起来像你想做一个for循环:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM