/*
Proyecto de Separacion de Clamshells
Simulacion de la pantalla TFT de acuerdo a mis necesidades y la del usuario
Valeria Chavez
*/
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
const int TFT_CS = 1;
const int TFT_MOSI = 41;
const int TFT_SCLK = 40;
const int TFT_MISO = 16;
const int TFT_LED = 6;
const int TFT_DC = 42;
const int TFT_RST = 2;
const int PIN_SENSOR = 12;
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST, TFT_MISO);
void configurarPantalla() {
tft.setRotation(3);
Serial.println("Pintando VERTICALMENTE");
tft.fillScreen(ILI9341_WHITE);
tft.setRotation(1);
Serial.println("Pintando horizontalmente");
tft.fillScreen(ILI9341_WHITE);
yield();
Serial.println("Fin de pintado");
//tft.setRotation(4);
}
void dibujarTexto(const char* titulo, int x0,int y0, const char* linea1, int x1, int y1,const char* linea2, int x2, int y2) {
tft.setRotation(2);
tft.setTextSize(3);
tft.setCursor(x0, y0);
tft.setTextColor(ILI9341_RED);
tft.println(titulo);
tft.setTextSize(2);
tft.setCursor(x1, y1); //x1=15 y1=100
tft.setTextColor(ILI9341_BLACK);
tft.println(linea1);
tft.setCursor(x2, y2); //x2=30, y2=150
tft.setTextColor(ILI9341_BLACK);
tft.println(linea2);
}
void dibujaMenuPrincipal() {
tft.setRotation(2); // Cambia la orientación de la pantalla. Ajusta entre 0, 1, 2, 3 para probar la que prefieras.
// Coordenadas y dimensiones del botón centrado de forma "automatica"
int boton_ancho = 100;
int boton_alto = 50;
int boton_x = (tft.width() - boton_ancho) / 2; // Centra horizontalmente
int boton_y = (tft.height() - boton_alto) / 2; // Centra verticalmente
// Dibuja el botón "INICIO" en verde con texto blanco
tft.fillRect(boton_x, boton_y, boton_ancho, boton_alto, ILI9341_GREEN);
tft.setCursor(boton_x + 20, boton_y + 15); // Ajusta el cursor para centrar el texto en el botón
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("INICIO");
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
tft.begin();
//tft.setRotation(3);
Serial.println("Hello, ESP32-S3!");
}
void loop() {
delay(10);
char MENU;
Serial.println("Ingrese (I) para iniciar"); //simulando como si fuese el bluetooth
// Si el bluetooth capta 'I', el programa inicia y se abre el submenu
// Si el bluetooth capta 'O', el programa se para y se regresa al menu principal
configurarPantalla();
dibujaMenuPrincipal();
//dibujarTexto("INICIO", 50, 150, "", 0, 0, "", 0, 0); //PARTE CORREGIDA
// Verifica si hay datos disponibles antes de leer
if (Serial.available() > 0) {
MENU = Serial.read(); // Lee un solo carácter del serial
if (MENU == 'I') { // Se muestra el submenu si se recibe 'I'
Serial.println("se seleccionó I");
PantallaSujetando(); // Caso cuando se sujete los chamshell
submenu();
delay(2000);
PantallaSeparando(); // Caso cuando se separe los clamshell
submenu();
delay(2000);
PantallaFinalizado(); // Caso cuando se finaliza el proceso de 1 clamshell
submenu();
delay(2000);
Serial.println("Ingrese 'O' para detener el proceso ");
//VERIFICAR Que ESPERA AL O
while(1){
if(Serial.available() > 0){
// Espera hasta que se ingrese un valor
MENU = Serial.read(); // Lee la entrada de nuevo
if (MENU == 'O') {
// Se detiene el proceso
Serial.println("Proceso detenido y regresando al menú principal.");
break;
}
}
}
}
}
}
void submenu() {
int botonAncho = 80; // Ancho del botón
int botonAlto = 40; // Alto del botón
int x = tft.width() - botonAncho - 10; // Posición x del botón (10 píxeles desde el borde derecho)
int y = tft.height() - botonAlto - 10; // Posición y del botón (10 píxeles desde el borde inferior)
// Dibujar el rectángulo del botón
tft.fillRect(x, y, botonAncho, botonAlto, ILI9341_RED);
tft.drawRect(x, y, botonAncho, botonAlto, ILI9341_BLACK); // Borde negro
// Configurar el texto "DETENER" en el centro del botón
tft.setCursor(x + 5, y + 12); // Ajustar la posición del texto dentro del botón
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("DETENER");
}
void PantallaSujetando() {
tft.setRotation(1);
configurarPantalla();
dibujarTexto("DETALLES:",15,25, "Ajustando",15,100, "Clamshell",30,150);
Serial.println("Se detecta objeto y se encuentra ajustando el clamshell");
}
void PantallaSeparando() {
tft.setRotation(1);
configurarPantalla();
dibujarTexto("DETALLES:",15,25,"Separando",15,100,"Clamshell",30,150);
Serial.println("Se detecta objeto y se encuentra separando el clamshell");
}
void PantallaFinalizado() {
tft.setRotation(1);
configurarPantalla();
dibujarTexto("DETALLES:",15,25,"Clamshell separado",15,100, "con exito!",25,150);
Serial.println("Fin del proceso");
}