expected unqualified id before 'if'

Hi Marc,
Are you sure about the block separation in this code? In particular, I can see a problem here:

      else
            {
              val = Serial.read();
              //Serial.print(val);
            }
        }
       switch (val){

The "val" variable is not initialized (it is just declared) outside of that "else" condition.
However, the program reaches that "switch" instruction even when the "else" code is not executed.
At that moment, "val" holds a random value and should not be used for a "switch" statement.
Hope this helps!
Riccardo