#define BUTTONPIN 2
#define LEDPIN 13
// By default, the LED is not lit.
boolean LED_State = false;
void setup() {
// put your setup code here, to run once:
pinMode(BUTTONPIN, INPUT_PULLUP); //defaule value: High/true
pinMode(LEDPIN, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// When the level of the BUTTONPIN is High(default value when unpressed)
// do nothing but waiting
while(digitalRead(BUTTONPIN))
;
// When the button is pressed, the LED_state is changed and expressed.
LED_State = !LED_State;
digitalWrite(LEDPIN, LED_State);
delay(300);
}