#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define TFT_DC 2
#define TFT_CS 15
#define BTN_PIN_1 34
#define BTN_PIN_2 35
#define BTN_PIN_3 32
#define ANALOG_PIN_1 13
#define ANALOG_PIN_2 12
#define ANALOG_PIN_3 14
#define ANALOG_PIN_4 17
#define ANALOG_PIN_5 27
#define ANALOG_PIN_6 26
#define ANALOG_PIN_7 25
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int xPos = 0;
int previousValues[7] = {0};
void setup(){
tft.begin();
tft.setRotation(1);
limpiar();
pinMode(BTN_PIN_1, INPUT_PULLUP);
pinMode(BTN_PIN_2, INPUT_PULLUP);
pinMode(BTN_PIN_3, INPUT_PULLUP);
}
void loop(){
// Leer el estado de los botones
if (digitalRead(BTN_PIN_1) == LOW) {
showSignals(0, 2);
delay(200); // Esperar para evitar el rebote del botón
}
if (digitalRead(BTN_PIN_2) == LOW) {
showSignals(2, 4);
delay(200); // Esperar para evitar el rebote del botón
}
if (digitalRead(BTN_PIN_3) == LOW) {
showSignals(4, 6);
delay(200); // Esperar para evitar el rebote del botón
}
// Leer el valor del voltaje de cada pin analógico y dibujar las señales correspondientes
int voltages[7] = {analogRead(ANALOG_PIN_1), analogRead(ANALOG_PIN_2), analogRead(ANALOG_PIN_3),
analogRead(ANALOG_PIN_4), analogRead(ANALOG_PIN_5), analogRead(ANALOG_PIN_6),
analogRead(ANALOG_PIN_7)};
for (int i = 0; i < 7; i++) {
// Escalar el voltaje si excede la altura de la pantalla
int voltageEscalado = map(voltages[i], 0, 4095, 0, tft.height());
if (voltageEscalado >= tft.height()) {
voltageEscalado = tft.height() - 1;
}
// Asignar un color diferente a cada señal
uint16_t color;
switch (i) {
case 0:
color = ILI9341_RED;
break;
case 1:
color = ILI9341_GREEN;
break;
case 2:
color = ILI9341_BLUE;
break;
case 3:
color = ILI9341_YELLOW;
break;
case 4:
color = ILI9341_MAGENTA;
break;
case 5:
color = ILI9341_CYAN;
break;
case 6:
color = ILI9341_WHITE;
break;
default:
color = ILI9341_WHITE;
}
tft.drawLine(xPos - 1, tft.height() - previousValues[i] - 1, xPos, tft.height() - voltageEscalado - 1, color);
previousValues[i] = voltageEscalado;
}
xPos++;
if (xPos >= tft.width()) {
xPos = 0;
limpiar();
}
delay(5);
}
void limpiar() {
tft.fillScreen(ILI9341_BLACK);
}
void showSignals(int start, int end) {
for (int i = 0; i < 7; i++) {
if (i >= start && i < end) {
// Mostrar la señal
} else {
// Ocultar la señal
}
}
}