Hello, how can I recover the int value of a ENUM type??
Thanks.
Hello, how can I recover the int value of a ENUM type??
Thanks.
Print it?
// Constants:-
enum{stop, reverse, forward};
// Variables:-
int direction;
void setup()
{
Serial.begin(115200);
direction = reverse; // direction now equals 1
Serial.print(direction);
}
void loop(){}
More info:- enum
pabusa:
Hello, how can I recover the int value of a ENUM type??
Why do you need to?
OldSteve:
// Constants:-
enum{stop, reverse, forward};
// Variables:-
int direction;
void setup()
{
Serial.begin(115200);
direction = reverse; // direction now equals 1
Serial.print(direction);
}
void loop(){}
More info:- [enum](http://en.cppreference.com/w/cpp/language/enum)
Thank you oldsteve, as simple as this ....
pabusa:
Thank you oldsteve, as simple as this ....
Yep. The members are numbered 0,1,2.....
When declaring the enum, it can also have a name like this:-
enum directions{stop, reverse, forward};
And you can set a value within the enum like this:-
enum directions{stop=1, reverse, forward};
Now the members are numbered 1,2,3
Or:-
enum{stop, reverse, forward=10, up, down};
And now the values are 0,1,10,11,12