1 // Example 02: Turn on LED while the button is pressed
4 const int BUTTON = 7; // the input pin where the
5 // pushbutton is connected
7 // val will be used to store the state
10 pinMode(LED, OUTPUT); // tell Arduino LED is an output
11 pinMode(BUTTON, INPUT); // and BUTTON is an input
14 val = digitalRead(BUTTON); // read input value and store it
15 // check whether the input is HIGH (button pressed)
17 digitalWrite(LED, HIGH); // turn LED ON
20 digitalWrite(LED, LOW);