c++ - Arduino代码错误,用户输入的LED闪烁

标签 c++ compiler-errors arduino arduino-uno

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

这是我编写的代码:

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++) { … }

关于c++ - Arduino代码错误,用户输入的LED闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61557531/

相关文章:

string - Haskell 中的 Data.Text 常量

javascript - Matlab 到 HTML5 WebSocket

java - 我正在尝试使用 Socket 连接到 URL,但只能通过提供 IP 地址(Java android)进行连接

c++ - 每个选项卡只看到一次 onload 事件

c - dev c++和在线编译器有什么区别?

c++ - 将 unique_ptr 传递给函数

optimization - 在 forall 循环中使用用户定义的函数

c - 如何在 Arduino 上将字符串转换为 uint8_t 数组?

c++ - 匿名命名空间中的 const 与 static const

c++ - 正则表达式检测边界,例如源代码行的注释