
图1 按钮连接到扩展板图

图2 扩展板原理图
3. arduino下的代码如下所示。
// 定义P0管脚
const int buttonPin = 33; // P0管脚对应的GPIO编号是33
void setup() {
// 初始化串口通信,用于输出结果
Serial.begin(115200);
// 设置P0管脚为输入模式
pinMode(buttonPin, INPUT);
}
void loop() {
// 读取P0管脚的电平状态
int buttonState = digitalRead(buttonPin);
// 输出读取到的状态到串口监视器
if (buttonState == 0) {
Serial.println("Button is not pressed");
}
if (buttonState == 1) {
Serial.println("Button is pressed");
}
delay(50);
}

