Perhaps I'm not very good with google search but I cannot figure out how to use enum with switch-case. The examples I've seen (including on this forum) look like this:
enum Color { UNDEF, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE };
void setup()
{
Color clr = RED;
switch (clr)
{
case UNDEF: break;
case RED: clr = BLUE; break;
case BLUE: clr = YELLOW; break;
// etc
default: break;
}
}
void loop()
{
}
However these examples do not seem practical since the enum instance is always hardcoded in them.
Is there something like Enum.Parse in the arduino IDE? since code like this will throw a compiler error
at Color clr = arg:
char *arg;
arg = //*Some output from some function*;
enum Color { UNDEF, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE };
Color clr = arg;
...
which obviously throws the error
cannot convert "char*" to "clr" in initialization
Is there a special trick I can use similar to Enum.Parse in C#? or am I better off just using "if, else if"?