Alright I'm back with some results.
HazardsMind:
No but you can do this.
#define Dud 0
#define Win 1
#define Lose 2
#define Accel 3
byte states[4] = {
Dud,Win,Lose,Accel};
void setup()
{
Serial.begin(115200);
switch(states[0])
{
case Dud:
//do nothing
break;
case Win:
// user wins
break;
case Lose:
//user loses
break;
case Accel:
//timer accelerates
break;
}
}
void loop()
{
}
Can you clarify this code a bit? For one, the array needs to be 2D (char states[4][6], not char states[4]) to work with my previously written code.
econjack:
The expression controlling a switch must resolve to an integral value. The code you posted wouldn't work because you are using string data which do not resolve to an integral data type. You could use:
char states[4][6] = {"Dud", "Win", "Lose", "Accel"};
int index;
// some code that determines the proper index to use...
char val = states[index][0];
switch (val) {
case 'D':
//do nothing
break;
case 'W':
// user wins
break;
case 'L':
//user loses
break;
case 'A':
//timer accelerates
break;
default:
Serial.println("I shouldn't be here.");
break;
}
I also find it useful to always have a *default* case in a *switch* expression.
This works perfectly! Thanks for the help!