stspringer

Using_enum_Days_of_The_Week_Demo_1

Aug 20th, 2023 (edited)
97
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. /*
  2. //written by John Guarnieri [email protected], [email protected], an enum demonstration Arduino script, enum_Days_Of_The_Week_1.ino 08_20_2023
  3. */
  4.  
  5. //DECLARATIONS
  6.  
  7. // due to naming conflicts you will need a scoped enumeration (enum class)
  8.  
  9. //0 - MONDAY, 1 - TUESDAY, 2 - WEDNESDAY, 3 - THURSDAY, 4 - FRIDAY, 5 - SATURDAY, 6 - SUNDAY // the compiler will assign numbers to the enumeration items
  10.  
  11. // enum due to naming conflicts you will need a scoped enumeration (enum class)
  12. enum class Day {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY};
  13.  
  14. 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
  15.  
  16. //long
  17. unsigned long lastTimeDayMondayWasShown = 0;
  18. const unsigned long WeekDayDelay = 1000; //1 second
  19.  
  20. //bool
  21. bool StopSerialprint = false;
  22.  
  23.  
  24. void setup() {
  25. Serial.begin(115200);
  26. }
  27.  
  28. void loop()
  29. {
  30. if (!StopSerialprint) //NOT StopSerialprint
  31. {
  32. if (millis() - lastTimeDayMondayWasShown >= WeekDayDelay)
  33. {
  34. lastTimeDayMondayWasShown = millis();
  35. //Day_Of_The_Week, MONDAY was set first by default in DECLARATIONS
  36. tellItLikeItIs();
  37. Day_Of_The_Week = Day::TUESDAY;
  38. tellItLikeItIs();
  39. Day_Of_The_Week = Day::FRIDAY;
  40. tellItLikeItIs();
  41. Day_Of_The_Week = Day::SATURDAY;
  42. tellItLikeItIs();
  43. Serial.println( );//just make a blank line if you were to print the days over again, without using the bool StopSerialprint
  44. Day_Of_The_Week = Day::MONDAY;//start over on MONDAY
  45. StopSerialprint = true;
  46. } //millis
  47. } //if
  48.  
  49. }//loop
  50.  
  51. //function
  52. void tellItLikeItIs()
  53. {
  54. switch (Day_Of_The_Week) // Day_Of_The_Week a variable to store the current state for Day
  55. {
  56. case Day::MONDAY :
  57. Serial.println("Mondays are bad.");
  58. break;
  59. case Day::TUESDAY: case Day:: WEDNESDAY: case Day:: THURSDAY://WEEKDAYS
  60. Serial.println("Midweek days are so-so.");
  61. break;
  62. case Day::FRIDAY :
  63. Serial.println("Fridays are better.");
  64. break;
  65. case Day::SATURDAY: case Day:: SUNDAY://WEEKEND DAYS
  66. Serial.println("Weekends are best.");
  67. break;
  68.  
  69. } //switch
  70. } //tellItLikeItIs
Advertisement
Comments
Add Comment
Please, Sign In to add comment