Happy_New_Year.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. //////////////////////////////////////////////////////////////////////
  2. // //
  3. // Programmname: Happy New Year //
  4. // Datum: 27.10.2023 //
  5. // Beschreibung: Es zählt von 10 bis 0 herunter und zeigt dann //
  6. // die Nachricht Happy New Year!!! an. //
  7. // //
  8. // 1. Autor: Nataliia Leonova 5088216 //
  9. // //
  10. // //
  11. //////////////////////////////////////////////////////////////////////
  12. ////////// Inkludierte Header-Dateien //////////
  13. #include "Happy_New_Year.h"
  14. ////////// Globale Variablen //////////
  15. ////////// Setup-Funktion //////////
  16. void setup(void) { // put your setup code here, to run once:
  17. Serial.begin(BAUDRATE);
  18. ////////// Lokale Variablen //////////
  19. ////////// GPIO Setup //////////
  20. ////////// Einmalige Anweisungen //////////
  21. happy_new_year_for();
  22. happy_new_year_while();
  23. }
  24. ////////// Loop-Funktion //////////
  25. void loop(void) { // put your main code here, to run repeatedly:
  26. ////////// Lokale Variablen //////////
  27. ////////// Hauptprogramm //////////
  28. happy_new_year_if();
  29. }
  30. ////////// Unterfunktionen / ISR //////////
  31. void happy_new_year_for(void) { // "for" solution for "Happy New Year"
  32. ////////// Lokale Variablen //////////
  33. char finalMessage[] = "Happy New Year!!!";
  34. char countMessage[] = "Countdown:";
  35. char stopCount = 10;
  36. char startCount = 0;
  37. ////////// Funktionsanweisungen //////////
  38. for (char i = startCount; i < stopCount; i++) {
  39. Serial.print(countMessage);
  40. Serial.println(stopCount - i);
  41. delay(1000);
  42. }
  43. Serial.print(finalMessage);
  44. return; // Beenden der Unterfunktion
  45. }
  46. void happy_new_year_while(void) { // "while" solution for "Happy New Year"
  47. ////////// Lokale Variablen //////////
  48. char finalMessage[] = "Happy New Year!!!";
  49. char countMessage[] = "Countdown:";
  50. char stopCount = 10;
  51. char startCount = 0;
  52. ////////// Funktionsanweisungen //////////
  53. char i = startCount;
  54. while (i < stopCount) {
  55. Serial.print(countMessage);
  56. Serial.println(stopCount - i);
  57. delay(1000);
  58. i++;
  59. }
  60. Serial.print(finalMessage);
  61. return; // Beenden der Unterfunktion
  62. }
  63. void happy_new_year_if(void) { // "if/else" solution for "Happy New Year"
  64. ////////// Lokale Variablen //////////
  65. static char finalMessage[] = "Happy New Year!!!";
  66. static char countMessage[] = "Countdown:";
  67. static char stopCount = 10;
  68. static char startCount = 0;
  69. ////////// Funktionsanweisungen //////////
  70. static char i = startCount;
  71. if (i < stopCount) {
  72. Serial.print(countMessage);
  73. Serial.println(stopCount-i);
  74. delay(1000);
  75. i++;
  76. }
  77. else if (i == stopCount)
  78. {
  79. Serial.println(finalMessage);
  80. i++;
  81. }
  82. return; // Beenden der Unterfunktion
  83. }