int LED = 8; // Sets LED = 8
int button = 7; // Sets button = 7;
int buttonpress = 0; // Sets status of button to 0 which is off
int on = 1; // If on = 0, LED is off. If on = 1 LED is on.
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)
{
on = on + 1;
if (on == 1)
{
digitalWrite (LED, HIGH); //Turns on LED
delay(200);
}
else
{
digitalWrite (LED, LOW); //Turns off LED
delay(200);
on = 0;
}
}
}