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.
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.
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.
yeah that's true.
But in thinking about why my code did not work i learned on how to use enum class.
So I can use this one for the switch case that does not need to be converted and maybe use the oldschool enum for the tracklist that i want to play which automatically gets converted to int.
btw I read about the enum class in the book "clean c++ 17" from stephan roth.