Enum in Switch Statement

MorganS:
An enum in C is just a different way of writing integer constants. Under this system the constant G will have the value 0. It won't be related to the ASCII value of 'G' in any way.

Now you can force it to use values you select in the enum. You could make G='G' but really, what's the point of that when Jacque's solution is perfect? You can even make it case-insensitive so the poor user doesn't have to hold down the SHIFT key...

  switch(inputString){

case "G":
    case "g":
      Serial.println("Got G");
      break;
    case "Q":
    case "q":
      Serial.println("42.42");
      break;

You can also make it case insensitive by using:

  • inCar = toupper((char)Serial.read());*

which gets rid of the lower case constants in the switch.