int red = 13;
int green = 12;
int button = 8;
void setup() {
//Sets the red and green leds as outputs and the button as an input
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(button, INPUT_PULLUP);
//Has the red light on at the start
}
void loop() {
//Checks if the button has been pushed
//Turns the red led off and the green led on
if (digitalRead(button) == LOW) {
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
}
//Turns the green led off and the red led on
else{
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
}
}