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