簡體   English   中英

Arduino 用戶輸入閃爍 LED 的代碼錯誤

[英]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),板:“Arduino/Genuino Uno”

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: 錯誤:在 ';' 之前預期 ')' 令牌

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

 ^

Blink_LED_user_Input_Times:36:19: 錯誤: 'i' 未在此 scope 中聲明

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

 ^

退出狀態 1 預期 ')' 在 ';' 之前令牌

此報告將在文件 -> 首選項中啟用“在編譯期間顯示詳細 output”選項的更多信息。

while循環中只能有一個條件

你的語法看起來像你想做一個for循環:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM