//BTNPIN defines the arduino input in to which
//the button is connected
const int BTNPIN = 2;
const int ledPin = 10;
//btnState stores the current button state (HIGH or LOW)
//initialize it to LOW so the LED stays off until the sketch
//reads a HIGH state for the button input
int btnState = LOW;
void setup() {
//the setup function runs once every time the arduino
//powers up or resets (after sketch update for example)
//initialize the digital pin ledPin as output
pinMode(ledPin, OUTPUT);
//initialize push button pin as an input
pinMode(BTNPIN, INPUT);
//set the initial state of the LED (off)
digitalWrite(ledPin, btnState);
}
// the loop function rns repeatedly as long as a sketch is
//loaded and the arduino has power.
void loop() {
//read the state of the button; it's a digital input,
//so possible returned values are HIGH or LOW.
btnState = digitalRead(BTNPIN)
//use the measured value to set the LED state
digitalWrite(ledPin, btnState);
//this whole function can be simplified to hte following
//single line of code:
//digitalWrite(ledPin, digitalRead(BTNPIN))
}