gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:56:40 25 4
gpt4 key购买 nike

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

这是我编写的代码:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com