#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define vertical 4
#define horizontal 34
#define pinUp 25
#define pinLeft 33
#define pinRight 27
#define pinDown 17
int arriba;
int derecha;
bool Estado1;
bool Estado2;
void setup() {
Serial.begin(115200);
pinMode(vertical, INPUT);
pinMode(horizontal, INPUT);
pinMode(pinUp, OUTPUT);
pinMode(pinLeft, OUTPUT);
pinMode(pinRight, OUTPUT);
pinMode(pinDown, OUTPUT);
tft.begin(); // inicializa pantalla
tft.setRotation(0); // establece posicion vertical con pines hacia abajo
tft.fillScreen(ILI9341_BLACK); // fondo de pantalla de color negro
tft.fillRect(0, 0, 240, 30, ILI9341_NAVY); // rectangulo azul naval a modo de fondo de titulo
tft.setTextColor(ILI9341_WHITE); // color de texto en blanco
tft.setTextSize(2); // escala de texto en 2
tft.setCursor(25,6); // ubica cursor
tft.print("Panel de control"); // imprime texto
tft.setCursor(24, 50);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("PRESIONA ALGUNA\n TECLA");
tft.setCursor(140, 170);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(7);
tft.println("=>");
tft.setCursor(20, 170);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(7);
tft.println("<=");
tft.setCursor(100, 100);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(7);
tft.println("^");
tft.setCursor(100, 240);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(7);
tft.println("v");
delay(1000);
}
void loop() {
arriba = analogRead(vertical);
derecha = analogRead(horizontal);
if(arriba>2048 && derecha == 2048){
Serial.println("Arriba");
}else if(arriba>2048 && derecha > 2048){
Serial.println("Arriba-Izquierda");
}else if(arriba == 2048 && derecha > 2048){
Serial.println("Izquierda");
}else if(arriba < 2048 && derecha > 2048){
Serial.println("Abajo-Izquierda");
}else if(arriba < 2048 && derecha == 2048){
Serial.println("Abajo");
}else if(arriba < 2048 && derecha < 2048){
Serial.println("Abajo-Derecha");
}else if(arriba == 2048 && derecha < 2048){
Serial.println("Derecha");
}else if(arriba > 2048 && derecha < 2048){
Serial.println("Arriba-Derecha");
}
if(arriba>2048){
digitalWrite(pinUp,HIGH);
tft.setCursor(100, 100);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(7);
tft.println("^");
}else if(arriba<2048){
digitalWrite(pinDown,HIGH);
tft.setCursor(100, 240);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(7);
tft.println("v");
}else{
digitalWrite(pinDown,LOW);
digitalWrite(pinUp,LOW);
tft.fillRect(100, 100, 125, 300, ILI9341_BLACK);
}
if(derecha<2048){
digitalWrite(pinRight,HIGH);
tft.setCursor(140, 170);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(7);
tft.println("=>");
}else if(derecha>2048){
digitalWrite(pinLeft,HIGH);
tft.setCursor(20, 170);
tft.setTextColor(ILI9341_YELLOW);
tft.setTextSize(7);
tft.println("<=");
}else{
digitalWrite(pinRight,LOW);
digitalWrite(pinLeft,LOW);
tft.fillRect(0, 170, 240, 200, ILI9341_BLACK);
}
delay(100);
}
/*
1.- Crear variables de lectura de los datos de la palanca
2.- Identificar los datos de salida de la palanca
3.- Inicializar los leds adecuadamente.
4.- Con lógica, establecer una dirección de lectura, ej- arriba, e imprimirla
5.- Establecer las demás posiciones, considerando las limitantes fisicas de la palanca
6.- Establecer mensajes en el monitor serial de acuerdo a las posiciones de la palanca
7.- Las posiciones deben ser excluyentes entre sí
8.- Prender los leds acorde a las restricciones excluyentes mencionadas anteriormente
*/