The switch - case structure checks for the first match.
If you read an "a" from the keyboard it will always find
you are building a "state machine" - specifically a "sequential state machine"
I found a simple example here that shows one way to do this -
and I've copied the code here: the loop uses a variable "state"
to keep track of which is the current state;
and each time a match is found the "state" variable is incremented.
/*
* Traffic lights example
*
* Red light to pin 7
* Yellow light to pin 6
* Green light to pin 5
*
* Arduino IDE 1.6.12
*/
// Pins
int red = 7, yellow = 6, green = 5;
// System variables
byte state = 0; // initial state
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
}
void loop() {
switch(state){
case 0:
digitalWrite(red, HIGH);
digitalWrite(yellow, LOW);
digitalWrite(green, LOW);
delay(10000);
state = 1;
break;
case 1:
digitalWrite(red, HIGH);
digitalWrite(yellow, HIGH);
digitalWrite(green, LOW);
delay(3000);
state = 2;
break;
case 2:
digitalWrite(red, LOW);
digitalWrite(yellow, LOW);
digitalWrite(green, HIGH);
delay(8000);
state = 3;
break;
case 3:
digitalWrite(red, LOW);
digitalWrite(yellow, HIGH);
digitalWrite(green, LOW);
delay(2000);
state = 0;
break;
default:
break;
} //state
} // loop