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.

148 lines
3.2 KiB

#include "TFT_eSPI.h"
#include "RTC_SAMD51.h"
#include "DateTime.h"
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;
String minuteString;
String hourString;
void setup() {
Serial.begin(115200);
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.
minute = now.minute();
hour = now.hour();
tft.begin();
tft.setRotation(3);
tft.setTextColor(TFT_BLACK);
tft.setTextSize(3);
while (!Serial)
{
tft.fillScreen(TFT_GREEN);
tft.drawString("Need serial com", 10, 10);
}
pinMode(WIO_KEY_A, INPUT_PULLUP);
pinMode(WIO_KEY_B, INPUT_PULLUP);
pinMode(WIO_KEY_C, INPUT_PULLUP);
pinMode(WIO_5S_PRESS, INPUT_PULLUP);
tft.fillRect(0,0,320,40,TFT_BLUE); // BANDEAU DU HAUT
tft.drawString("+ - RAZ",5,10);
if (now.minute() < 10)
minuteString = "0" + String(now.minute());
else
minuteString = String(now.minute());
if (now.hour() < 10)
hourString = "0" + String(now.hour());
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);
attachInterrupt(WIO_KEY_C, add, FALLING);
attachInterrupt(WIO_KEY_B, substract, FALLING);
attachInterrupt(WIO_KEY_A, resetInit, FALLING);
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++;
if (affluence <= maxAffluence)
tft.fillRect(0,41,320,240,TFT_GREEN);
else
tft.fillRect(0,41,320,240,TFT_RED);
tft.drawString("affluence: " + String(affluence), 10, 75);
tft.drawString("visiteurs: " + String(visiteurs), 10, 100);
}
void substract()
{
if (affluence != 0)
{
affluence--;
if (affluence <= maxAffluence)
tft.fillRect(0,41,320,240,TFT_GREEN);
else
tft.fillRect(0,41,320,240,TFT_RED);
tft.drawString("affluence: " + String(affluence), 10, 75);
tft.drawString("visiteurs: " + String(visiteurs), 10, 100);
}
}
void resetInit()
{
resetTime = millis();
Serial.println("RESETINIT");
}
void reset()
{
Serial.println("RESET");
if (millis() - resetTime <= 5000)
{
affluence = 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);
resetTime = 0;
}
}