const int switchPin = 10; // 按键开关连接引脚10
void setup() {
pinMode(switchPin, INPUT); // 设置引脚10为输入模式
Serial.begin(9600); // 设置串口波特率为9600
}
void loop() {
int switchValue = 0; //定义变量并赋初值为0
switchValue = digitalRead(switchPin); //读取引脚10的值
Serial.print(" Value of switch = "); //输出到串口监视器
Serial.println(switchValue); //将读取的按键值输出到串口监视器
}