Files
2024-09-27 01:22:07 +08:00

35 lines
1.1 KiB
C++
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
读取引脚2的数字输入将结果显示在串口监视器中
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a name:
//引脚2连接有按键开关给它一个名字
int pushButton = 2;
// the setup routine runs once when you press reset:
//当你按下复位按钮后setup流程运行一次
void setup() {
// initialize serial communication at 9600 bits per second:
//串口通讯初始化每秒9600位
Serial.begin(9600);
// make the pushbutton's pin an input:
//设置按键引脚为输入
pinMode(pushButton, INPUT);
}
// the loop routine runs over and over again forever:
// loop 流程会永远的反复运行
void loop() {
// read the input pin:
//读取输入引脚:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
// 显示按键状态
Serial.println(buttonState);
delay(1); // delay in between reads for stability 为确保程序稳定运行进行短暂停止
}