//电阻为必需,不然5V就接地了
int pushButton=2;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);//初始化串行通信,设置波特率(通信速率)。
  pinMode(pushButton,INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  int buttonState=digitalRead(2);
  Serial.println(buttonState);//将数据发送到串行端口。
  delay(100);
}
//内部上拉电阻(Pull-up resistor)是一种电阻,它将输入引脚连接到供电电压(通常是 5V),从而将引脚的电平拉高到高电平状态。这样做的目的是确保输入引脚在未连接到外部信号源时保持稳定的高电平状态。
$abcdeabcde151015202530354045505560fghijfghij