编写程序,当按下按钮时,小灯不亮!!松手时,小灯亮!! 编程时注意:引脚与课堂给定的图不同!!! 观察下图,接通灯的引脚号为 1 ,接按钮的引脚号为 2 。 int buttonState; void setup() { // initialize the LED pin as an output: pinMode( 3 , OUTPUT ); // initialize the pushbutton pin as an input: pinMode( 4 ,INPUT); } void loop() { // read the state of the pushbutton value: buttonState = digitalRead( 5 ); // check if the pushbutton is pressed. If it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED off: digitalWrite( 6 , 7 ); } else { // turn LED on: digitalWrite( 8 , 9 ); } }