【发布时间】:2021-03-05 05:48:51
【问题描述】:
在 YT 教程之后,我已经学习了 3 天的 Arduino 使用方法。我目前正在学习串行监视器的输入输出。
运行一次循环后,串行监视器自动输入一个 0 并注册为输入,然后返回接受用户输入。
我的意思的截图:
下面是代码:
//inputs
int blinks;
String question = "How many times would you like the LED to blink? ";
//LED
int LEDPin = 8;
//while loop
int i = 1;
//delay
int delayTime = 500;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LEDPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(question);
//this waits for an input <while serial is empty>
while (Serial.available() == 0) {
};
//this reads the input
blinks = Serial.parseInt();
Serial.println(blinks);
//output
while (i <= blinks) {
digitalWrite(LEDPin, HIGH);
delay(delayTime);
digitalWrite(LEDPin, LOW);
delay(delayTime);
Serial.println(i);
i++;
};
i = 1;
}
【问题讨论】:
标签: arduino integer arduino-uno serial-monitor