From 3eb03ba5fa3fd5ee0f25d8e7c2e97cc90370b679 Mon Sep 17 00:00:00 2001 From: Auguste FLEURY Date: Thu, 16 May 2024 10:52:48 +0200 Subject: [PATCH] :green_heart: --- script.ino => script/script.ino | 132 ++++++++++++++++++-------------- 1 file changed, 74 insertions(+), 58 deletions(-) rename script.ino => script/script.ino (66%) diff --git a/script.ino b/script/script.ino similarity index 66% rename from script.ino rename to script/script.ino index 401df70..f13532c 100644 --- a/script.ino +++ b/script/script.ino @@ -4,18 +4,25 @@ TFT_eSPI tft; RTC_SAMD51 rtc; -unsigned int affluence = 0; -unsigned int visiteurs = 0; -const unsigned short maxAffluence = 10; -int resetTime; + +/*########################################################*/ + DateTime now = DateTime(F(__DATE__), F(__TIME__)); short minute; short hour; short second = 0; +unsigned int actuel = 0; +unsigned int visiteurs = 0; +const unsigned short maxAffluence = 15; +int resetTime; + String minuteString; String hourString; +/*########################################################*/ + + void setup() { Serial.begin(115200); @@ -23,18 +30,15 @@ void setup() { rtc.adjust(now); now = rtc.now(); - second = now.second() + 5; //Il y a un décalage de 5 secondes entre les secondes réelles et celles de la librairy. + second = now.second(); minute = now.minute(); hour = now.hour(); tft.begin(); tft.setRotation(3); - tft.setTextColor(TFT_BLACK); tft.setTextSize(3); - - while (!Serial) - { + while (!Serial){ tft.fillScreen(TFT_GREEN); tft.drawString("Need serial com", 10, 10); } @@ -46,22 +50,25 @@ void setup() { tft.fillRect(0,0,320,40,TFT_BLUE); // BANDEAU DU HAUT - tft.drawString("+ - RAZ",5,10); - if (now.minute() < 10) + tft.drawString("+ - raz",5,10); + if (now.minute() < 10){ minuteString = "0" + String(now.minute()); - else + } + else{ minuteString = String(now.minute()); - if (now.hour() < 10) + } + if (now.hour() < 10){ hourString = "0" + String(now.hour()); - else + } + else{ hourString = String(now.hour()); - + } tft.drawString(hourString + ":" + minuteString,230,10); tft.fillRect(0,41,320,240,TFT_GREEN); // Carré du bas - tft.drawString("affluence: " + String(affluence), 10, 75); - tft.drawString("visiteurs: " + String(visiteurs), 10, 100); + tft.drawString("affluence: " + String(actuel), 20, 75); + tft.drawString("visiteurs: " + String(visiteurs), 20, 100); attachInterrupt(WIO_KEY_C, add, FALLING); attachInterrupt(WIO_KEY_B, substract, FALLING); @@ -69,59 +76,38 @@ void setup() { attachInterrupt(WIO_5S_PRESS, reset, FALLING); } -void loop() { - - delay(1000); - second++; - Serial.println(second); - if (second%60 == 0) - { - minute++; - if (minute%60 == 0) - hour++; - if (hour == 24) - hour = 0; - - tft.fillRect(0,0,320,40,TFT_BLUE); // BANDEAU DU HAUT - tft.drawString("+ - RAZ",5,10); - if (now.minute() < 10) - minuteString = "0" + String(minute); - else - minuteString = String(minute); - if (now.hour() < 10) - hourString = "0" + String(hour); - else - hourString = String(hour); - - tft.drawString(hourString + ":" + minuteString,230,10); - } -} + void add() { visiteurs++; - affluence++; + actuel++; - if (affluence <= maxAffluence) + if (actuel <= maxAffluence){ tft.fillRect(0,41,320,240,TFT_GREEN); - else + } + else{ tft.fillRect(0,41,320,240,TFT_RED); - tft.drawString("affluence: " + String(affluence), 10, 75); - tft.drawString("visiteurs: " + String(visiteurs), 10, 100); + } + tft.drawString("affluence: " + String(actuel), 20, 75); + tft.drawString("visiteurs: " + String(visiteurs), 20, 100); } + void substract() { - if (affluence != 0) + if (actuel != 0) { - affluence--; + actuel--; - if (affluence <= maxAffluence) + if (actuel <= maxAffluence){ tft.fillRect(0,41,320,240,TFT_GREEN); - else + } + else{ tft.fillRect(0,41,320,240,TFT_RED); - tft.drawString("affluence: " + String(affluence), 10, 75); - tft.drawString("visiteurs: " + String(visiteurs), 10, 100); + tft.drawString("affluence: " + String(actuel), 20, 75); + tft.drawString("visiteurs: " + String(visiteurs), 20, 100); + } } } @@ -136,12 +122,42 @@ void reset() Serial.println("RESET"); if (millis() - resetTime <= 5000) { - affluence = 0; + actuel = 0; visiteurs = 0; tft.fillRect(0,41,320,240,TFT_GREEN); - tft.drawString("affluence: " + String(affluence), 10, 75); - tft.drawString("visiteurs: " + String(visiteurs), 10, 100); + tft.drawString("affluence: " + String(actuel), 20, 75); + tft.drawString("visiteurs: " + String(visiteurs), 20, 100); resetTime = 0; } } +void bar(){ + tft.fillRect(0,0,320,40,TFT_BLUE); + tft.drawString("+ - raz",5,10); + if (now.minute() < 10) + minuteString = "0" + String(minute); + else + minuteString = String(minute); + if (now.hour() < 10) + hourString = "0" + String(hour); + else + hourString = String(hour); + + tft.drawString(hourString + ":" + minuteString,230,10); +} + +void loop() { + delay(1000); + second++; + Serial.println(second); + if (second%60 == 0) + { + minute++; + if (minute%60 == 0) + hour++; + if (hour == 24) + hour = 0; + + bar(); + } +}