项目地址:https://www.tinkercad.com/things/fxAUiYvu7aG
const int buttonPin = 2; //定义GPIO2输入开关按钮电平 const int ledPin = 7; //定义GPIO7为电平输出 int buttonState = 0; //GPIO2初使电平为低电平 void setup() { pinMode(ledPin, OUTPUT); //设置输出引脚 pinMode(buttonPin, INPUT); //设置输入引脚 } void loop() { buttonState = digitalRead(buttonPin); //读取输入电平 if (buttonState == HIGH) { //如输入高电平 digitalWrite(ledPin, HIGH); //则输出高电平 }else { digitalWrite(ledPin, LOW); //否则输出低电平 } }