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.
164 lines
3.3 KiB
164 lines
3.3 KiB
#include "TFT_eSPI.h"
|
|
#include "RTC_SAMD51.h"
|
|
#include "DateTime.h"
|
|
|
|
TFT_eSPI tft;
|
|
RTC_SAMD51 rtc;
|
|
|
|
/*########################################################*/
|
|
|
|
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);
|
|
|
|
|
|
|
|
rtc.adjust(now);
|
|
now = rtc.now();
|
|
second = now.second();
|
|
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(actuel), 20, 75);
|
|
tft.drawString("visiteurs: " + String(visiteurs), 20, 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 add()
|
|
{
|
|
visiteurs++;
|
|
actuel++;
|
|
|
|
if (actuel <= maxAffluence){
|
|
tft.fillRect(0,41,320,240,TFT_GREEN);
|
|
}
|
|
else{
|
|
tft.fillRect(0,41,320,240,TFT_RED);
|
|
}
|
|
tft.drawString("affluence: " + String(actuel), 20, 75);
|
|
tft.drawString("visiteurs: " + String(visiteurs), 20, 100);
|
|
}
|
|
|
|
|
|
void substract()
|
|
{
|
|
if (actuel != 0)
|
|
{
|
|
actuel--;
|
|
|
|
if (actuel <= maxAffluence){
|
|
tft.fillRect(0,41,320,240,TFT_GREEN);
|
|
}
|
|
else{
|
|
tft.fillRect(0,41,320,240,TFT_RED);
|
|
tft.drawString("affluence: " + String(actuel), 20, 75);
|
|
tft.drawString("visiteurs: " + String(visiteurs), 20, 100);
|
|
}
|
|
}
|
|
}
|
|
|
|
void resetInit()
|
|
{
|
|
resetTime = millis();
|
|
Serial.println("RESETINIT");
|
|
}
|
|
|
|
void reset()
|
|
{
|
|
Serial.println("RESET");
|
|
if (millis() - resetTime <= 5000)
|
|
{
|
|
actuel = 0;
|
|
visiteurs = 0;
|
|
tft.fillRect(0,41,320,240,TFT_GREEN);
|
|
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();
|
|
}
|
|
}
|