bool PROGRAM_BOOTING() {
switch (WandStartSequence) {
case bootPhase0:
PROGRAM_BOOT_BLINK_L();
break;
case bootPhase1:
PROGRAMM_BOOT_KL();
break;
case bootPhase2:
PROGRAM_Vent_bootUp();
break;
case bootPhase3:
BLINK_FUNCTION_LED_OF_SEGMENT(BarGraph_Segment, 0);
break;
}
if(WandStartSequence == bootPhase3){
Serial.println("Booted");
return true;
}
else{
Serial.println("NOT Booted");
return false;
}
}
and in the loop function for debugging this:
Serial.println(WandStartSequence);
Then i switched to the newer enum class. But I cannot print the current value neither as string nor as int. Do i have to convert them?
And another question is that i am also using a soundchip for playing music in my program. the soundchip plays the tracks according to the provided number as int.
i there a way that i can assign the tracknames as enum class like ambient = 1, idle = 5, ....
and the use this variables for better readability? like playSong(idle), instead of playSong(5)?
enum class BootSequence {
bootPhase0,
bootPhase1,
bootPhase2,
bootPhase3,
};
BootSequence WandStartSequence = BootSequence::bootPhase0;
//switch function with functions above
bool PROGRAM_BOOTING() {
switch (WandStartSequence) {
case BootSequence::bootPhase0:
PROGRAM_BOOT_BLINK_L();
break;
case BootSequence::bootPhase1:
PROGRAMM_BOOT_KL();
break;
case BootSequence::bootPhase2:
PROGRAM_Vent_bootUp();
break;
case BootSequence::bootPhase3:
BLINK_FUNCTION_LED_OF_SEGMENT(BarGraph_Segment, 0);
break;
}
if(WandStartSequence == BootSequence::bootPhase3){
Serial.println("Booted");
return true;
}
else{
Serial.println("NOT Booted");
return false;
}
}
void loop() {
Serial.println(WandStartSequence); //-> not working
[... more code]
}
So in short:
How can I Serial print the current text value of my enum class.
Can i assign the enum class variables different ints like in the old enum?
As I wrote the soundchip member functions take an int as input.
In this way I can organize my soundfiles on top of my scetch with readable names and when i want to play them later i assign the name to the memeberfunction which hopefully gets converted to an int, so that the function can play the corresponding track.
Because it doesn't work the way you want it to. Why not use the thing that actually works instead of worrying about something you read and didn't understand.
read about that it is saver to use the enum class, because of not messing up with namespaces for example. and i am just learning c++ so why not use the current stuff instead of older?
On the why = in C++, an enum allows for implicit promotion to its underlying integral type, typically an int, for compatibility with C. This means that values of an enum type can be used interchangeably with integers in expressions, assignments, and function arguments without requiring an explicit cast.
However, an enum class (strongly-typed enumeration) introduced in C++11 does not allow such implicit promotion. Enum class values are strongly scoped and must be explicitly cast to their underlying type to be used as integers. This design choice was made to enhance type safety by preventing unintended conversions and limiting the scope of enumerators.
So your issue (as other explained) was that you did no longer benefit from the implicit promotion to an int which print would know how to handle.
So if you're going to cast them everywhere anyway then it really doesn't bring much benefit does it? It sounds like it just creates extra syntax in this case.
But OP read about something that said it was safer. Now they want it to work the unsafe way. If OP is ok with the cast then what's the point of using the enum class? If OP wants an enum class then he shouldn't be trying to make it an int.
enum class allows multiple enum types to use the duplicate member names without conflict. The same names can even have different underlying integer values in different enum classes.