const int BUTTON = 5; //Connect button to D5
const int LED1=4; //Connect LED to D4
int ledState = LOW; //Default state of LED is low
int previousButtonState;
int presentButtonState;
void setup()
{
pinMode(BUTTON,INPUT); //Configure Button as input
pinMode(LED1, OUTPUT); //Configure LED as output
}
void loop()
{ //Read the button state
presentButtonState = digitalRead(BUTTON);
if(presentButtonState==HIGH) //If Button state is high
{
digitalWrite(LED1, HIGH); //Turn ON LED
}
else //If button state is low
{
digitalWrite(LED1, LOW); //Turn LOW LED
}
}