|
楼主 |
发表于 2017-9-21 22:35
|
显示全部楼层
图好像看不清 我手动复制一遍
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
boolean ledState=false;
// variables will change: // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// read the state of the pushbutton value:
while(digitalRead(buttonPin)==HIGH){};
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (ledState == true) {
// turn LED on:
digitalWrite(ledPin, LOW);
ledState=!ledState;
}
else {
// turn LED off:
digitalWrite(ledPin, HIGH);
ledState=!ledState;
}
delay(500);
} |
|