#include <DS3231.h>//biblioteca para o RCT
#include "TouchScreen.h"//biblioteca para touch
#include <Adafruit_GFX.h> // Biblioteca Gráfica Adafruit
#include <MCUFRIEND_kbv.h> // Bibllioteca para controle do lcd
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeSerifBold9pt7b.h>
#include <Fonts/FreeSerifBoldItalic9pt7b.h>
#include <Fonts/FreeSansBold9pt7b.h>
DS3231 rtc(SDA,SCL);//iniciar DS3231 criando o objeto rct
Time t;
#define YP A1
#define XM A2
#define YM 7
#define XP 6
#define TS_MINX 112
#define TS_MINY 103
#define TS_MAXX 972
#define TS_MAXY 961
#define MINPRESSURE 10
#define MAXPRESSURE 1000
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
#define PRETO 0x0000
#define AZUL 0x001F
#define VERMELHO 0xF800
#define VERDE 0x07E0
#define CIANO 0x07FF
#define AMARELO 0xFFE0
#define BRANCO 0xFFFF
#define CINZENTO 0x7BEF
#define LARANJA 0xFD20
#define CINZENTO_C 0xC618
MCUFRIEND_kbv tft;
void setup()
{
uint16_t ID = tft.readID();
tft.begin(ID);
rtc.begin();
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(10, 19, 5); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(9, 5, 2018);// Set the date to January 1st, 2014
}
void pag_inicial()
{
tft.setRotation(1);
tft.fillScreen(PRETO);//fundo a preto
tft.fillRect(15,80,290,80,VERMELHO);
tft.drawRect(15,80,290,80,BRANCO);
tft.setCursor(106,90);
tft.setFont(&FreeMonoBold9pt7b);
tft.setTextColor(BRANCO);
tft.setTextSize(1);
tft.print("CASO SEJE\n");
tft.setCursor(30,127);
tft.setTextColor(BRANCO);
tft.setTextSize(2);
tft.print("SURDO / MUDO\n");
tft.setCursor(94,150);
tft.setTextColor(BRANCO);
tft.setTextSize(1);
tft.print("CLIQUE AQUI!");
tft.drawLine(0,180,320,180,LARANJA);
tft.setFont(&FreeSerifBoldItalic9pt7b);
tft.setCursor(47,205);
tft.setTextSize(1);
tft.setTextColor(BRANCO);
tft.print("ELEVADOR INTELIGENTE");
tft.setCursor(30,225);
tft.setTextSize(1);
tft.setTextColor(BRANCO);
tft.print("AQUELE QUE SE ADAPTA A SI!");
}
TSPoint waitTouch()
{
TSPoint p;
do {
p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
} while((p.z < MINPRESSURE )|| (p.z > MAXPRESSURE));
p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);
return p;
}
void botoes_pisos()
{
tft.fillRect(20,40,270,50,CINZENTO_C);
tft.setFont(&FreeSerifBold9pt7b);
tft.setCursor(102,68);
tft.setTextColor(AZUL);
tft.setTextSize(2);
tft.print("PISO 0");
tft.setCursor(90,84);
tft.setTextSize(1);
tft.setTextColor(AZUL);
tft.print("Sala de jogos/Bar");
tft.fillRect(20,100,270,50,CINZENTO_C);
tft.setCursor(102,128);
tft.setTextColor(AZUL);
tft.setTextSize(2);
tft.print("PISO 1");
tft.setCursor(102,144);
tft.setTextSize(1);
tft.setTextColor(AZUL);
tft.print("Quar.101-115");
tft.fillRect(20,160,270,50,CINZENTO_C);
tft.setCursor(102,186);
tft.setTextColor(AZUL);
tft.setTextSize(2);
tft.print("PISO 2");
tft.setCursor(102,206);
tft.setTextSize(1);
tft.setTextColor(AZUL);
tft.print("Quar.201-215");
}
void mostrar_minuto()
{
if(t.min<10)
{
do
{
tft.setCursor(90,15);
tft.print(".0");
tft.print(t.min,DEC);
delay(1000);
}while(t.min<10);
}
else
{
do
{
tft.setCursor(90,15);
tft.print(t.min,DEC);
delay(1000);
}while(t.min<10);
}
}
void loop()
{
tft.fillScreen(PRETO);
pag_inicial();
tft.setFont();
t = rtc.getTime();
tft.setCursor(5,15);
tft.setTextSize(2);
tft.print("HORA: ");
tft.setCursor(65,20);
tft.setTextSize(2);
tft.print(t.hour,DEC);
mostrar_minuto();
tft.setCursor(170,20);
tft.setTextSize(2);
tft.print("TEMP.: ");
tft.setCursor(230,20);
tft.setTextSize(2);
//tft.print(temperatura);
tft.setCursor(291,16);
tft.print('o');
tft.setCursor(300,20);
tft.print("C");
tft.drawLine(0,60,320,60,LARANJA);
tft.setCursor(5,50);
tft.setTextSize(2);
tft.print("DATA: ");
tft.setCursor(60,30);
tft.setTextSize(2);
tft.print(t.date,DEC);
tft.print('.');
tft.print(rtc.getMonthStr());
tft.print('.');
tft.print(t.year,DEC);
TSPoint p = waitTouch();
if((p.x>20) && (p.x<=300) && (p.y>110) && (p.y<=190))
{
tft.fillScreen(PRETO);
tft.setFont(&FreeSerifBold9pt7b);
tft.setCursor(5,20);
tft.setTextColor(BRANCO);
tft.setTextSize(1);
tft.print("HORA: ");
tft.setCursor(170,20);
tft.setTextSize(1);
tft.setTextColor(BRANCO);
tft.print("TEMP.:");
tft.setCursor(291,16);
tft.print('o');
tft.setCursor(300,20);
tft.print("C");
tft.setFont(&FreeSansBold9pt7b);
tft.drawLine(0,40,320,40,LARANJA);
tft.setCursor(60,120);
tft.setTextColor(VERMELHO);
tft.setTextSize(2);
tft.print("Qual o piso\n");
tft.setCursor(40,160);
tft.setTextColor(VERMELHO);
tft.setTextSize(2);
tft.print("Que deseja ir?");
delay(5000);
tft.fillScreen(PRETO);
tft.setFont(&FreeSerifBold9pt7b);
tft.setCursor(5,20);
tft.setTextColor(BRANCO);
tft.setTextSize(1);
tft.print("HORA: ");
tft.setCursor(170,20);
tft.setTextSize(1);
tft.setTextColor(BRANCO);
tft.print("TEMP.:");
tft.setCursor(291,16);
tft.print('o');
tft.setCursor(300,20);
tft.print("C");
tft.drawLine(0,30,320,30,LARANJA);
botoes_pisos();
TSPoint p = waitTouch();
if((p.x>20) && (p.x<=290) && (p.y>40) && (p.y<=110))
{
if(piso_elevador==microswitch0)
{
tft.fillScreen(PRETO);
tft.setFont(&FreeSansBold9pt7b);
tft.setCursor(60,120);
tft.setTextColor(VERMELHO);
tft.setTextSize(2);
tft.print("Encontra-se\n");
tft.setCursor(70,160);
tft.setTextColor(VERMELHO);
tft.setTextSize(2);
tft.print("Nesse piso!");
delay(4000);
botoes_pisos();
}
else
{
if(piso_elevador!=microswitch0)
{
do
{
Stepper_elevador.step(-512);
tft.fillScreen(PRETO);
tft.setFont(&FreeMonoBold9pt7b);
tft.setCursor(30,50);
tft.setTextSize(2);
tft.setTextColor(VERDE);
tft.print("DESCENDO PARA\n o PISO 0");
}while(microswitch0!=1);
tft.fillScreen(PRETO);
tft.setFont(&FreeMonoBold9pt7b);
tft.setCursor(30,60);
tft.setTextSize(2);
tft.setTextColor(VERDE);
tft.print("CHEGOU AO \n o PISO 0");
delay(1000);
Stepper_porta.step(-512);
tft.fillScreen(PRETO);
tft.setFont(&FreeMonoBold9pt7b);
tft.setCursor(30,60);
tft.setTextSize(2);
tft.setTextColor(VERDE);
tft.print("PORTA ABERTA");
}
}
tft.fillScreen(PRETO);
tft.setFont(&FreeMonoBold9pt7b);
tft.setCursor(30,50);
tft.setTextSize(2);
tft.setTextColor(VERDE);
tft.print("SUBINDO PARA\n o PISO 1");
delay(5000);
}
}
}