Happy_New_Year.cpp 3.2 KB

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