#include <SD.h>
#include <SPI.h>
#include <Adafruit_ILI9341.h>
#include <Keypad.h>
//#include <WiFi.h>
//#include <WiFiUdp.h>
// Define Pins
#define SD_CS 4
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
// Define Variables
int pot1 = A0;
int pot2 = A1;
int x, y; // Variables for touch coordinates
// Create TFT Object
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Create SD Object
File root;
// Define Keyboard Pins
#define ROWS 4
#define COLS 4
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte rowPins[ROWS] = {22, 23, 24, 25}; // Filas conectadas a pines digitales
byte colPins[COLS] = {26, 27, 28, 29}; // Columnas conectadas a pines analógicos
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
bool displayMessages = true;
const char* ssid = "TuSSID"; // Reemplaza con el nombre de tu red Wi-Fi
const char* password = "TuClave"; // Reemplaza con la contraseña de tu red Wi-Fi
const char* receiverIP = "192.168.1.101"; // Reemplaza con la dirección IP del ESP32 receptor
const int receiverPort = 8888; // Puerto al que el ESP32 receptor estará escuchando
const int potentiometerPin = 34; // Pin del potenciómetro
//WiFiUDP Udp;
//IPAddress localIP;
void setup() {
// Initialize Serial
Serial.begin(9600);
// Initialize TFT
tft.begin();
// Initialize SD
Serial.print("Initializing SD card...");
if (!SD.begin(SD_CS)) {
Serial.println("Initialization failed!");
return;
}
Serial.println("Initialization done.");
root = SD.open("/");
// Initialize Wi-Fi
//WiFi.begin(ssid, password);
//while (WiFi.status() != WL_CONNECTED) {
//delay(1000);
//Serial.println("Connecting to Wi-Fi...");
//}
//Serial.println("Wi-Fi connection successful");
// Get local IP address of ESP32
//localIP = WiFi.localIP();
//Serial.print("Local IP address: ");
//Serial.println(localIP);
// Initialize UDP
//Udp.begin(12345); // Start UDP service on port 12345
}
void loop() {
if (displayMessages) {// Muestra los mensajes iniciales en la pantalla solo una vez
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(50, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("HOLA OPERADOR");
tft.setCursor(20, 80);
tft.print("Elija una opcion:");
tft.setCursor(0, 160);
tft.print("(A) Realizar todas las pruebas");
delay(2000);
// Espera hasta que se presione una tecla
char key = keypad.getKey();
if (key) {
displayMessages = false; // Detiene la visualización de mensajes
// Iniciar el proceso de pruebas aquí
if (key == 'A' || key == 'a') {
// Usuario eligió la opción A, proceder con Paso 1 y luego Paso 2
performStep1();
performStep2();
}
}
}
}
void performStep1() {
// Mostrar el número de paso
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(20, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Antes de empezar");
// Mostrar instrucciones Paso 1 (Página 1)
tft.setCursor(20, 80);
tft.print("Instrucciones:");
delay(2000);
tft.setCursor(0, 140);
tft.print(" Enciende el equipo");
delay(3000);
tft.setCursor(0, 200);
tft.print(" Verifica la temperatura de trabajo (60 C)");
delay(3000);
tft.setCursor(20,300);
tft.print("Comenzemos...");
delay(3000);
// Cambiar a Página 2 de instrucciones Paso 1
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 40);
tft.print("Prueba del S. Boom");
tft.setCursor(0, 80);
delay(3000);
tft.print("Identifica el Joystick para el Sistema Boom:");
delay(3000);
tft.setCursor(0,140);
tft.print("Acelera el equipo a 1900 RPM");
delay(3000);
tft.setCursor(0, 200);
tft.print("Mueve el brazo hastael punto maximo de levante");
tft.setCursor(60, 280);
delay(3000);
tft.print("Siguiente...");
delay(3000);
// Cambiar a la Página 3 de Instrucciones
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0,20);
tft.print("Prueba del S. Boom");
delay(3000);
tft.setCursor(0, 60);
tft.print("Inicia el calado delsistema por 12 segundos");
delay(3000);
tft.setCursor(0,120);
tft.print("La presion debe oscilar entre: ");
tft.setCursor(0,180);
delay(3000);
tft.print("5366 - 5801 PSI");
delay(3000);
tft.setCursor(60, 260);
tft.print("Comenzemos...");
delay(2000);
// Mostrar variación del potenciómetro 1 durante 13 segundos
unsigned long startTime = millis();
int pot1ValAtStart = analogRead(pot1);
unsigned long duration = 13000; // 13 segundos
while (millis() - startTime < duration) {
int pot1Val = map(analogRead(pot1), 0, 1023, 0, 7000);
// Muestra la variación del potenciómetro 1 en una página de la pantalla
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0,60);
tft.print("Sensor del S. Boom:");
tft.setCursor(0, 100);
tft.print("Presion: " + String(pot1Val) + " psi");
tft.setCursor(0, 180);
tft.print("Continue por favor..");
delay(500); // Actualiza cada medio segundo
}
// Proyectar el estado del sistema Paso 1
int finalPot1Val = analogRead(pot1);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(10, 60);
tft.print("Estado del S. Boom:");
if (finalPot1Val >= 784.2026 && finalPot1Val <= 847.7747) {
//784,20 = 5366 psi
//847,77 = 5801 psi
tft.setCursor(0, 120);
tft.print("Sist. EN BUEN ESTADO");
tft.setCursor(0,160);
tft.print("(Dentro de 5366-5801 psi)");
tft.setCursor(0,220);
tft.print("Siguiente prueba...");
} else {
tft.setCursor(0, 120);
tft.print("Sist. EN MAL ESTADO");
tft.setCursor(0,160);
tft.print("(Fuera de 5366-5801 psi)");
delay(3000);
tft.setCursor(0,220);
tft.print("Siguiente prueba...");
}
// Espera un momento antes de continuar al Paso 2
delay(5000);
}
void performStep2() {
// Mostrar el número de paso
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Prueba del S. Buquet");
delay(3000);
// Mostrar instrucciones Paso 2 (Página 1)
tft.setCursor(0,80);
tft.print("Identifica el Joystick para el Sistema Buquet:");
delay(3000);
tft.setCursor(0,140);
tft.print("Acelera el equipo a 1900 RPM");
delay(3000);
tft.setCursor(0, 200);
tft.print("Mueve el cucharon hasta el punto maximo de retraccion");
tft.setCursor(60, 280);
delay(3000);
tft.print("Siguiente...");
delay(3000);
// Cambiar a Página 2 de instrucciones Paso 2
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0,20);
tft.print("Prueba del S. Buquet");
delay(3000);
tft.setCursor(0, 60);
tft.print("Inicia el calado delsistema por 12 segundos");
delay(3000);
tft.setCursor(0,120);
tft.print("La presion debe oscilar entre: ");
delay(3000);
tft.setCursor(20,180);
tft.print("5221 - 5656 PSI");
delay(3000);
tft.setCursor(60, 260);
tft.print("Comenzemos...");
delay(2000);
// Mostrar variación del potenciómetro 2 durante 13 segundos
unsigned long startTime = millis();
int pot2ValAtStart = analogRead(pot2);
unsigned long duration = 13000; // 13 segundos
while (millis() - startTime < duration) {
int pot2Val = map(analogRead(pot2), 0, 1023, 0, 7000);
// Muestra la variación del potenciómetro 2 en una página de la pantalla
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 60);
tft.print("Sensor del S. Buquet");
tft.setCursor(0,100);
tft.print("Presion: " + String(pot2Val) + " psi");
tft.setCursor(0,180);
tft.print("Continue por favor..");
delay(500); // Actualiza cada medio segundo
}
// Proyectar el estado del sistema Paso 2
int finalPot2Val = analogRead(pot2);
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 60);
tft.print("Estado del S. Buquet:");
if (finalPot2Val >= 763.0119 && finalPot2Val <= 826.5840) {
// Presion es 5656 = 826.5840
// Presion es 5221 = 763,0119
tft.setCursor(0, 120);
tft.print("Sist. EN BUEN ESTADO");
tft.setCursor(0,160);
tft.print("(Dentro de 5221-5656 psi)");
tft.setCursor(0,220);
tft.print("Siguiente prueba...");
} else {
tft.setCursor(0, 120);
tft.print("Sist. EN MAL ESTADO");
tft.setCursor(0,160);
tft.print("(Fuera de 5221-5656 psi)");
tft.setCursor(0,220);
tft.print("Siguiente prueba...");
}
// Espera un momento antes de continuar
delay(5000);
}