#include <SD.h>
#include <SPI.h>
#include <Adafruit_ILI9341.h>
// Define Pins
#define SD_CS 4
#define TFT_CS 10
#define TFT_DC 9
#define TFT_RST 8
#define START_BUTTON_PIN 2 // Pin para el botón "START"
#define NEXT_BUTTON_PIN 3 // Pin para el botón "SIGUIENTE"
// Define Variables
int pot1 = A0;
int pot2 = A1;
int pot1Val;
int pot2Val;
// Create TFT Object
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
// Create SD Object
File root;
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("/");
}
void loop() {
// Read Potentiometer Values
pot1Val = analogRead(pot1);
pot2Val = analogRead(pot2);
// Draw Start Button
tft.fillScreen(ILI9341_BLACK);
tft.fillRoundRect(20, 20, 200, 60, 10, ILI9341_BLUE);
tft.setCursor(50, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("START");
// Wait for the "START" button to be pressed
while (digitalRead(START_BUTTON_PIN) == HIGH) {
delay(1000);
}
// Step 1
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(50, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("PASO 1");
// Record Potentiometer Values for 25 Seconds
unsigned long startTime = millis();
while (millis() - startTime < 25000) {
pot1Val = analogRead(pot1);
pot2Val = analogRead(pot2);
delay(10);
}
// Check if Potentiometer Values are Within Range
if (pot1Val >= 4500 && pot1Val <= 6500 && pot2Val >= 4500 && pot2Val <= 6500) {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(50, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("PASO 1 EN CORRECTO ESTADO");
} else {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(50, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("PASO 1: EN MAL ESTADO");
}
// Draw Next Button
tft.fillRoundRect(20, 100, 200, 60, 10, ILI9341_BLUE);
tft.setCursor(50, 120);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("SIGUIENTE");
// Wait for the "SIGUIENTE" button to be pressed
while (digitalRead(NEXT_BUTTON_PIN) == HIGH) {
delay(50);
}
// Step 2
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(50, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("PASO 2");
// Record Potentiometer Values for 25 Seconds
startTime = millis();
while (millis() - startTime < 25000) {
pot1Val = analogRead(pot1);
pot2Val = analogRead(pot2);
delay(10);
}
// Check if Potentiometer Values are Within Range
if (pot1Val >= 4500 && pot1Val <= 6500 && pot2Val >= 4500 && pot2Val <= 6500) {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(50, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("PASO 2 EN CORRECTO ESTADO");
} else {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(50, 40);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("PASO 2: EN MAL ESTADO");
}
// Resto del código sin cambios...
}
Loading
ili9341-cap-touch
ili9341-cap-touch