#include <LiquidCrystal_I2C.h>
//boton a
#define butt 15
//boton s
#define butt1 5
//boton w
#define butt2 18
//boton d
#define butt3 19
int cont_x = 0;
int cont_y = 0;
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0X27,16, 2);
int lastButtonState = LOW;
int lastButtonState1 = LOW;
int lastButtonState2 = LOW;
int lastButtonState3 = LOW;
int pos_x_pac = 1;
int pos_y_pac = 0;
int pos_x_com = 5;
int pos_y_com = 0;
int estado = 0;
byte BocaAbierta[8] = {
0b01110,
0b11101,
0b11110,
0b11100,
0b11100,
0b11110,
0b11111,
0b01110
};
byte replace[8] = {
0b00000,
0b00000,
0b00000,
0b10100,
0b01000,
0b10100,
0b00000,
0b00000,
};
byte comida[8] = {
0b00000,
0b00000,
0b00000,
0b11100,
0b11100,
0b11100,
0b00000,
0b00000,
};
void paint();
void setup() {
// put your setup code here, to run once:
pinMode(butt1, INPUT);
pinMode(butt1, INPUT);
pinMode(butt2, INPUT);
pinMode(butt3, INPUT);
Serial.begin(115200);
Serial.println("Hello, ESP32!");
lcd.init();
lcd.backlight();
lcd.setCursor(3,1);
delay(1000);
lcd.print("BIENVENIDO");
lcd.setCursor(0,0);
lcd.createChar(0, BocaAbierta);
lcd.createChar(1, comida);
lcd.createChar(2, replace);
delay(2000);
}
void loop() {
int buttonState = digitalRead(butt);
int buttonState1 = digitalRead(butt1);
int buttonState2 = digitalRead(butt2);
int buttonState3 = digitalRead(butt3);
if (buttonState == HIGH && buttonState1 == LOW&& buttonState2 == LOW&& buttonState3 == LOW&& lastButtonState == LOW) {
boton1();
}
if (buttonState1 == HIGH && buttonState == LOW&& buttonState2 == LOW&& buttonState3 == LOW&& lastButtonState1 == LOW) {
boton2();
}
if (buttonState2 == HIGH && buttonState1 == LOW&& buttonState == LOW&& buttonState3 == LOW&& lastButtonState2 == LOW) {
boton3();
}
if (buttonState3 == HIGH&& buttonState1 == LOW&& buttonState2 == LOW&& buttonState == LOW&& lastButtonState3 == LOW) {
boton4();
}
}
void paint()
{
lcd.setCursor(pos_x_com,pos_y_com);
lcd.write((byte)1);
}
void boton1()
{
lcd.clear();
if (estado == 0)
{
paint();
}
if (estado == 1)
{
lcd.setCursor(pos_x_com,pos_y_com);
lcd.print(" ");
}
cont_x += 1;
pos_x_pac = cont_x;
if(pos_x_pac < 15)
{
lcd.setCursor(pos_x_pac,pos_y_pac);
lcd.write((byte)0);
}
if(pos_x_pac == pos_x_com && pos_y_pac == pos_y_com){
estado = 1;
}
if(pos_x_pac == 15)
{
cont_x = 1;
pos_x_pac = cont_x;
lcd.setCursor(pos_x_pac,pos_y_pac);
lcd.write((byte)0);
}
delay(100);
}
void boton2()
{
lcd.clear();
if (estado == 0)
{
paint();
}
if (estado == 1)
{
lcd.setCursor(pos_x_com,pos_y_com);
lcd.print(" ");
}
cont_x -= 1;
pos_x_pac = cont_x;
if(pos_x_pac > 0)
{
lcd.setCursor(pos_x_pac,pos_y_pac);
lcd.write((byte)0);
}
if(pos_x_pac == pos_x_com && pos_y_pac == pos_y_com){
estado = 1;
}
if(pos_x_pac == 0)
{
cont_x = 14;
pos_x_pac = cont_x;
lcd.setCursor(pos_x_pac,pos_y_pac);
lcd.write((byte)0);
}
delay(100);
}
void boton3()
{
lcd.clear();
if (estado == 0)
{
paint();
}
if (estado == 1)
{
lcd.setCursor(pos_x_com,pos_y_com);
lcd.print(" ");
}
cont_y += 1;
pos_y_pac = cont_y;
if(pos_y_pac < 2)
{
lcd.setCursor(pos_x_pac,pos_y_pac);
lcd.write((byte)0);
}
if(pos_x_pac == pos_x_com && pos_y_pac == pos_y_com){
estado = 1;
}
if(pos_y_pac == 2)
{
cont_y = 0;
pos_y_pac = cont_y;
lcd.setCursor(pos_x_pac,pos_y_pac);
lcd.write((byte)0);
}
delay(100);
}
void boton4()
{
lcd.clear();
if (estado == 0)
{
paint();
}
if (estado == 1)
{
lcd.setCursor(pos_x_com,pos_y_com);
lcd.print(" ");
}
cont_y -= 1;
pos_y_pac = cont_y;
if(pos_y_pac > -1)
{
lcd.setCursor(pos_x_pac,pos_y_pac);
lcd.write((byte)0);
}
if(pos_x_pac == pos_x_com && pos_y_pac == pos_y_com){
estado = 1;
}
if(pos_y_pac == -1)
{
cont_y = 1;
pos_y_pac = cont_y;
lcd.setCursor(pos_x_pac,pos_y_pac);
lcd.write((byte)0);
}
delay(100);
}