boolean pushButton;void setup() {// put your setup code here, to run once:pinMode(2,INPUT_PULLUP);pinMode(13,OUTPUT);}void loop() {// put your main code here, to run repeatedly:pushButton = digitalRead(2);if (pushButton) { //if pushButton==1,btn is not pusheddigitalWrite(13,HIGH);} else {digitalWrite(13,LOW);}}
按钮按下灯灭,不按灯亮