int LED = 8; // Sets LED = 8
int button = 7; // Sets button = 7;
int buttonpress = 0; // Sets status of button to 0 which is off
void setup()
{
pinMode(LED, OUTPUT); //Controls digital Pin 8 which controls LED
pinMode (button, INPUT); //Controls digital Pin 7 which controls button
}
void loop()
{
buttonpress=digitalRead(button); // Checks that button has been pressed
if (buttonpress == HIGH)
{
digitalWrite (LED, HIGH); //Turns on LED
delay(500);
digitalWrite (LED, LOW); //Turns off LED
buttonpress = 0;
}
else
{
digitalWrite(LED, LOW); //the LED shouldn't light up
}
}