#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
// Pines CS para cada pantalla
#define CS_1 10
#define CS_2 9
#define CS_3 8
#define CS_4 7
#define CS_5 6
#define CS_6 5
// Pines analógicos para potenciómetros
#define POT_SPEED A0
#define POT_RPM A1
#define POT_FUEL A2
#define POT_TEMP A3
#define POT_VOLTAGE A4
#define POT_PRESSURE A5
// Configuración de las pantallas
Adafruit_ILI9341 tft1 = Adafruit_ILI9341(CS_1, 9);
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(CS_2, 9);
Adafruit_ILI9341 tft3 = Adafruit_ILI9341(CS_3, 9);
Adafruit_ILI9341 tft4 = Adafruit_ILI9341(CS_4, 9);
Adafruit_ILI9341 tft5 = Adafruit_ILI9341(CS_5, 9);
Adafruit_ILI9341 tft6 = Adafruit_ILI9341(CS_6, 9);
// Valores simulados
int speedValue, rpmValue, fuelValue, tempValue, voltageValue, pressureValue;
void setup() {
// Inicializar las pantallas
tft1.begin();
tft2.begin();
tft3.begin();
tft4.begin();
tft5.begin();
tft6.begin();
// Configuración de pantalla
initScreen(tft1, "Velocímetro");
initScreen(tft2, "Tacómetro");
initScreen(tft3, "Combustible");
initScreen(tft4, "Temp. Agua");
initScreen(tft5, "Voltaje");
initScreen(tft6, "Presión Aceite");
Serial.begin(9600);
}
void loop() {
// Leer valores de potenciómetros
speedValue = analogRead(POT_SPEED);
rpmValue = analogRead(POT_RPM);
fuelValue = analogRead(POT_FUEL);
tempValue = analogRead(POT_TEMP);
voltageValue = analogRead(POT_VOLTAGE);
pressureValue = analogRead(POT_PRESSURE);
// Mapear valores
int speedMapped = map(speedValue, 0, 1023, 0, 200); // Velocidad: 0-200 km/h
int rpmMapped = map(rpmValue, 0, 1023, 0, 8000); // RPM: 0-8000
int fuelMapped = map(fuelValue, 0, 1023, 0, 100); // Combustible: 0-100%
int tempMapped = map(tempValue, 0, 1023, 40, 120); // Temperatura: 40-120 °C
int voltageMapped = map(voltageValue, 0, 1023, 10, 15); // Voltaje: 10-15V
int pressureMapped = map(pressureValue, 0, 1023, 0, 100); // Presión: 0-100 PSI
// Actualizar pantallas
updateGauge(tft1, speedMapped, "km/h");
updateGauge(tft2, rpmMapped, "RPM");
updateGauge(tft3, fuelMapped, "%");
updateGauge(tft4, tempMapped, "°C");
updateGauge(tft5, voltageMapped, "V");
updateGauge(tft6, pressureMapped, "PSI");
delay(500); // Refresco cada 500ms
}
// Función para inicializar cada pantalla
void initScreen(Adafruit_ILI9341 &tft, const char *title) {
tft.setRotation(3);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 10);
tft.println(title);
}
// Función para actualizar un gauge
void updateGauge(Adafruit_ILI9341 &tft, int value, const char *unit) {
tft.fillRect(0, 50, 320, 120, ILI9341_BLACK); // Limpiar área del gauge
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(4);
tft.setCursor(80, 90);
tft.print(value);
tft.print(" ");
tft.print(unit);
}