#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#include <Adafruit_FT6206.h>
#include <Wire.h>
#define TFT_DC 42
#define TFT_CS 1
#define TFT_RST 2
#define TFT_MOSI 41
#define TFT_CLK 40
#define TFT_MISO 16
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
Adafruit_FT6206 touch = Adafruit_FT6206();
// Coordenadas y tamaño del círculo azul táctil
int CirculoX = 30;
int CirculoY = 15;
int Radio = 5;
int x,y;
void setup() {
Serial.begin(115200);
Wire.begin(20, 21);
SPI.begin(TFT_CLK, TFT_MISO, TFT_MOSI, TFT_CS); // Inicializa SPI con los pines especificados
tft.begin();
tft.setRotation(4);
tft.fillScreen(ILI9341_BLACK);
// Dibujar el ícono de advertencia
// drawWarningIcon();
// Dibujar el círculo azul
// drawTouchCircle();
// Mostrar el mensaje de error
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(5, 60);
tft.print("No hay mas Chamels");
tft.setCursor(0, 80);
tft.print("Presione el boton azul");
if (!touch.begin(40)) { // Sensibilidad de la pantalla táctil
Serial.println("No se detectó la pantalla táctil.");
while(1);
}
}
void loop() {
/* if (touch.touched()) {
// Obtiene el punto de toque
TS_Point p = touch.getPoint();
// Transforma las coordenadas para la orientación de la pantalla
x = map(p.y, 0, 320, 0, tft.width());
y = map(p.x, 0, 240, tft.height(), 0);
if(touchButtom()){
Serial.println("Boton presionado");
}
delay(100);
}
*/
}
// Función para dibujar el ícono de advertencia
void drawWarningIcon() {
int centerX = 50;
int centerY = 30;
int triangleHeight = 40;
int halfBase = 20;
// Dibujar el triángulo amarillo
tft.fillTriangle(centerX, centerY - triangleHeight / 2, centerX - halfBase, centerY + triangleHeight / 2, centerX + halfBase, centerY + triangleHeight / 2, ILI9341_YELLOW);
// Dibujar el signo de exclamación
tft.fillRect(centerX - 2, centerY - 10, 5, 15, ILI9341_BLACK);
tft.fillCircle(centerX, centerY + 10, 3, ILI9341_BLACK);
}
// Función para dibujar el círculo azul táctil
void drawTouchCircle() {
tft.fillCircle(CirculoX, CirculoY, Radio, ILI9341_BLUE);
tft.drawCircle(CirculoX, CirculoY, Radio, ILI9341_WHITE);
}
bool touchButtom(){
int dx = x - CirculoX;
int dy = y - CirculoY;
int distanceSquared = dx * dx + dy * dy;
return distanceSquared <= Radio * Radio;
}