#include <Arduino_GFX_Library.h>
#include <SPI.h>
#include <map> // Agrega la biblioteca <map> para usar std::map
#include <BluetoothSerial.h>
#define TFT_SCK 18
#define TFT_MOSI 23
#define TFT_MISO 19
#define TFT_CS 22
#define TFT_DC 21
#define TFT_RESET 17
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
BluetoothSerial SerialBT;
Arduino_ESP32SPI bus = Arduino_ESP32SPI(TFT_DC, TFT_CS, TFT_SCK, TFT_MOSI, TFT_MISO);
Arduino_ILI9341 tft = Arduino_ILI9341(&bus, TFT_RESET, 1);
#define COLOR_BLACK 0x0000 // Negro (R=0, G=0, B=0)
#define COLOR_WHITE 0xFFFF // Blanco (R=255, G=255, B=255)
#define COLOR_BLUE 0x00F8 // Azul (R=0, G=0, B=255)
#define COLOR_RED 0xF800 // Rojo (R=255, G=0, B=0)
#define COLOR_GREEN 0x07E0 // Verde (R=0, G=255, B=0)
#define COLOR_ORANGE 0x03FF // Naranja (R=255, G=165, B=0)
#define COLOR_PURPLE 0xF81F // Morado (R=128, G=0, B=128)
#define COLOR_YELLOW 0xFFE0 // Amarillo (R=255, G=255, B=0)
std::map<String, uint16_t> colorMap = {
{"yellow", COLOR_BLUE},
{"cian", COLOR_RED},
{"purple", COLOR_GREEN},
{"orange", COLOR_ORANGE},
{"green", COLOR_PURPLE},
{"blue", COLOR_YELLOW},
{"black", COLOR_BLACK},
{"white", COLOR_WHITE}
};
uint16_t currentBackgroundColor = COLOR_WHITE; // Inicialmente el fondo es blanco
void setup() {
Serial.begin(115200);
SerialBT.begin("ESP32LJ"); // Nombre del dispositivo Bluetooth
tft.begin();
tft.fillScreen(COLOR_WHITE);
tft.setRotation(1);
Serial.println("El dispositivo ha iniciado. ¡Puedes emparejarlo con Bluetooth!");
}
void loop() {
// Manejo de Bluetooth
if (SerialBT.available()) {
String message = SerialBT.readString();
// Limpiar la cadena de mensaje eliminando espacios en blanco y caracteres no imprimibles
message.trim(); // Eliminar espacios en blanco al principio y al final
message.replace("\r", ""); // Eliminar retorno de carro
message.replace("\n", ""); // Eliminar nueva línea
// Verificar si el mensaje está en el mapa
if (colorMap.find(message) != colorMap.end()) {
currentBackgroundColor = colorMap[message];
}
// Mostrar mensaje en cualquier caso
tft.fillScreen(currentBackgroundColor);
tft.setCursor(10, 10);
tft.setTextColor(COLOR_BLACK);
tft.setTextSize(2);
tft.println("Mensaje: " + message);
}
}