I put the switch case at the bottom of the code.
const int buttonPin = 10; // the number of the pushbutton pin
const int ledPin = 12; // the number of the red LED pin
const int ledPin2 = 8; // the number of the green LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int mes = 0; // to keep track of what led is on/off in the loop.
void setup() {
// initialize the outputs and inputs for the code:
pinMode(ledPin, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
//turning the loop around from 1-0 and 0-1 using the mes int
if (buttonState==HIGH && mes==0){
mes=1;
}
else if(buttonState==HIGH && mes==1){
mes=0;
}
//turns red LED on if the button is pressed:
if(buttonState==HIGH && mes==0){
digitalWrite(ledPin2, HIGH);
delay(500); //half a second delay before red LED turns off
digitalWrite(ledPin2, LOW);
buttonState=LOW;
}
//changes LED from red to green
else if (buttonState==HIGH && mes==1){
digitalWrite(ledPin,HIGH);
delay(500);// half a second delay before turning off
digitalWrite(ledPin,LOW);
buttonState=LOW;
}
if(buttonState==LOW){
digitalWrite(ledPin, LOW);
digitalWrite(ledPin2,LOW);
} // switch statemnt for when the button isn't pressed the LEDS to stay on
switch (mes) {
case 1:
if (buttonState == HIGH){
buttonState = LOW;
digitalWrite (ledPin2,HIGH);
digitalWrite (ledPin,LOW);// after the button is let go turn on red LED and turn off green LED
delay (100);
break;
}
case 2:
digitalWrite (ledPin,LOW);
digitalWrite (ledPin2,HIGH); // second time after the button is let go green LED on red off
}
}