You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
5.4 KiB

#include "TFT_eSPI.h"
#include "RTC_SAMD51.h"
#include "DateTime.h"
RTC_SAMD51 rtc;
int X_MAX = 320;
int Y_MAX = 240;
TFT_eSPI tft;
int visit_total = 0; // Initialize visit_total to 0
int affluence = 0; // Initialize affluence to 0
int ancien_visit_total = 0;
int ancien_affluence = 0;
int y = Y_MAX/5;
int background = TFT_GREEN;
int etatmessage15 = 0;
DateTime now = DateTime(F(__DATE__), F(__TIME__));
void setup() {
rtc.begin();
tft.begin();
tft.setRotation(3); // Set the screen orientation
tft.fillScreen(background); // Green background
Serial.begin(115200);
while (!Serial)
{
tft.setTextColor(TFT_BLACK);
tft.setTextSize(3);
tft.drawString("Need Serial Com", 10, 100);
}
tft.setTextColor(TFT_GREEN);
tft.drawString("Need Serial Com", 10, 100);
pinMode(WIO_KEY_A, INPUT_PULLUP);
pinMode(WIO_KEY_B, INPUT_PULLUP);
pinMode(WIO_KEY_C, INPUT_PULLUP);
pinMode(WIO_5S_PRESS, INPUT_PULLUP);
affiche();
affBandeauBleu();
affHeure();
rtc.adjust(now);
Serial.setTimeout(10);
}
void loop() {
visiteur();
affHeure();
message15();
message();
}
void affBandeauBleu() {
tft.fillRect(0, 0, X_MAX, y, TFT_BLUE);
tft.drawChar(10, 10, '+', TFT_BLACK, TFT_BLUE, 3);
tft.drawChar(80, 10, '-', TFT_BLACK, TFT_BLUE, 3);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(3);
tft.drawString("RAZ", 155, 10);
tft.drawChar(275, 10, ':', TFT_BLACK, TFT_BLUE, 3);
//sprintf(&s,"%d + %d = %d", a, b, c);
}
void affHeure() {
tft.setTextColor(TFT_BLUE);
tft.drawNumber(now.hour(), 240, 10);
tft.drawNumber(now.minute(), 285, 10);
now = rtc.now();
tft.setTextColor(TFT_BLACK);
tft.drawNumber(now.hour(), 240, 10);
tft.drawNumber(now.minute(), 285, 10);
}
void message(){
String val;
val = Serial.readString();
Serial.print(val);
if(val != NULL){
tft.setTextColor(TFT_BLACK);
tft.setTextSize(3);
tft.drawString("Nouveau Message !", 10, 50);
}
}
void message15(){
if(now.minute() == 0 || now.minute() == 15 || now.minute() == 30 || now.minute() == 45 || now.minute() == 60){
if(etatmessage15 == 0 ){
Serial.println("--------");
Serial.print("heure : ");
Serial.print(now.hour());
Serial.print(":");
Serial.println(now.minute());
Serial.print("visiteur : ");
Serial.println(visit_total);
Serial.print("affluence : ");
Serial.println(affluence);
Serial.println("--------");
etatmessage15 = 1;
}
}
if(now.minute() != 0 && now.minute() != 15 && now.minute() != 30 && now.minute() != 45 && now.minute() != 60 ){
etatmessage15 = 0;
}
}
void visiteur() {
int etat = 0;
if (digitalRead(WIO_KEY_B) == LOW) {
ancien_affluence = affluence;
affluence = affluence -1; // Decrease affluence
if(affluence < 0){
affluence = 0;
}
if(affluence <= 10){
background = TFT_GREEN;
tft.fillScreen(background); // Green background
affiche();
affBandeauBleu();
affHeure();
}
efface();
affiche();
}
else if (digitalRead(WIO_KEY_C) == LOW) {
ancien();
affluence = affluence +1; // Increase affluence
visit_total = visit_total +1; // Increment visit_total
if(affluence == 11)
tone(WIO_BUZZER, 442);
if(affluence > 10){
background = TFT_RED;
tft.fillScreen(background); // Green background
affiche();
affBandeauBleu();
noTone(WIO_BUZZER);
affHeure();
}
efface();
affiche();
}
else if (digitalRead(WIO_KEY_A) == LOW) {
tft.setTextColor(TFT_BLACK);
tft.setTextSize(3);
tft.drawString("Confirmez ?", 110, 200);
etat = compteur();
if(etat == 1){
ancien();
visit_total = 0;
affluence = 0;
etat = 0;
Serial.println("remise à 0 !!! ");
Serial.println("--------");
Serial.print("heure : ");
Serial.print(now.hour());
Serial.print(":");
Serial.println(now.minute());
Serial.print("visiteur : ");
Serial.println(visit_total);
Serial.print("affluence : ");
Serial.println(affluence);
Serial.println("--------");
}
tft.setTextColor(background);
tft.setTextSize(3);
tft.drawString("Confirmez ?", 110, 200);
efface();
affiche();
background = TFT_GREEN;
tft.fillScreen(background); // Green background
affiche();
affBandeauBleu();
affHeure();
}
delay(200);
}
void ancien(){
ancien_visit_total = visit_total;
ancien_affluence = affluence;
}
void efface(){
tft.setTextColor(background);
tft.setTextSize(3);
tft.drawString("visit_total", 10, 100);
tft.drawNumber(ancien_visit_total, 250, 100);
tft.drawString("affluence", 10, 150);
tft.drawNumber(ancien_affluence, 250, 150);
}
void affiche(){
tft.setTextColor(TFT_BLACK);
tft.setTextSize(3);
tft.drawString("visit_total", 10, 100);
tft.drawNumber(visit_total, 250, 100);
tft.drawString("affluence", 10, 150);
tft.drawNumber(affluence, 250, 150);
}
int compteur(){
int i = 5;
while( i > 0){
delay(1000);
i--;
if(digitalRead(WIO_5S_PRESS) == LOW){
return 1;
}
}
return 0;
}