Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- //written by John Guarnieri [email protected], [email protected], an enum demonstration Arduino script, enum_Days_Of_The_Week_1.ino 08_20_2023
- */
- //DECLARATIONS
- // due to naming conflicts you will need a scoped enumeration (enum class)
- //0 - MONDAY, 1 - TUESDAY, 2 - WEDNESDAY, 3 - THURSDAY, 4 - FRIDAY, 5 - SATURDAY, 6 - SUNDAY // the compiler will assign numbers to the enumeration items
- // enum due to naming conflicts you will need a scoped enumeration (enum class)
- enum class Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY};
- Day Day_Of_The_Week = Day::MONDAY; // a variable, Day_Of_The_Week, to store the current Day for tellItLikeItIs() Day_Of_The_Week, MONDAY first
- //long
- unsigned long lastTimeDayMondayWasShown = 0;
- const unsigned long WeekDayDelay = 1000; //1 second
- //bool
- bool StopSerialprint = false;
- void setup() {
- Serial.begin(115200);
- }
- void loop()
- {
- if (!StopSerialprint) //NOT StopSerialprint
- {
- if (millis() - lastTimeDayMondayWasShown >= WeekDayDelay)
- {
- lastTimeDayMondayWasShown = millis();
- //Day_Of_The_Week, MONDAY was set first by default in DECLARATIONS
- tellItLikeItIs();
- Day_Of_The_Week = Day::TUESDAY;
- tellItLikeItIs();
- Day_Of_The_Week = Day::FRIDAY;
- tellItLikeItIs();
- Day_Of_The_Week = Day::SATURDAY;
- tellItLikeItIs();
- Serial.println( );//just make a blank line if you were to print the days over again, without using the bool StopSerialprint
- Day_Of_The_Week = Day::MONDAY;//start over on MONDAY
- StopSerialprint = true;
- } //millis
- } //if
- }//loop
- //function
- void tellItLikeItIs()
- {
- switch (Day_Of_The_Week) // Day_Of_The_Week a variable to store the current state for Day
- {
- case Day::MONDAY :
- Serial.println("Mondays are bad.");
- break;
- case Day::TUESDAY: case Day:: WEDNESDAY: case Day:: THURSDAY://WEEKDAYS
- Serial.println("Midweek days are so-so.");
- break;
- case Day::FRIDAY :
- Serial.println("Fridays are better.");
- break;
- case Day::SATURDAY: case Day:: SUNDAY://WEEKEND DAYS
- Serial.println("Weekends are best.");
- break;
- } //switch
- } //tellItLikeItIs
Advertisement
Comments
-
- A simple enum demo script for Arduino, to help people understand enum and how to use it.
Add Comment
Please, Sign In to add comment