Doing some playing with switch case. The following recognizes the case when it is typed but the call to the void function doesn't work. The Serial.print part does so I know I have it somewhat right. Is that something that isn't allowed?
The idea behind the test was to replace a ton of IF statements. I have 7 direction functions that are called from IF statements comparing against serial input. It works perfectly but I want to keep learning and improving it.
So, can you not call a void function from a switch case?
byte state;
void setup() {
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0) // Checks whether data is coming from the serial port
{
state = Serial.read(); // Reads the data from the serial port
}
switch (state)
{
case '1': void hermon(); Serial.println("1");
break;
case '2': void steve(); Serial.println("2");
break;
}
}
void hermon()
{
Serial.println("1 was pressed");
}
void steve()
{
Serial.print("2 was pressed");
}