#include <Keypad.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define ledrojo 13
const uint8_t ROWS = 4;
const uint8_t COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
uint8_t colPins[COLS] = {7, 4, A2, A3};
uint8_t rowPins[ROWS] = {12, 11, 10, 9};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
int botonAuno = 0;
int botonAdos = 0;
typedef enum GameScreen
{
INICIO = 0,
LOGO,
TITLE,
GAMEPLAY,
ENDING
} GameScreen;
GameScreen menuUno = INICIO;
void setup()
{
lcd.init();
lcd.backlight();
pinMode(ledrojo, OUTPUT);
Serial.begin(9600);
}
void printMenu(const char *text)
{
//lcd.clear();
lcd.setCursor(0, 0);
lcd.print(text);
}
void loop()
{
char key = keypad.getKey();
ControlBotonA(key);
switch (menuUno)
{
case INICIO:
printMenu("INICIO");
break;
case LOGO:
printMenu("LOGO");
break;
case TITLE:
printMenu("TITLE");
break;
case GAMEPLAY:
printMenu("GAMEPLAY");
break;
case ENDING:
printMenu("ENDING");
break;
default:
break;
}
}
void ControlBotonA(char key)
{
int velocidadPulsacion = 15;
if (key == 'A')
{
for (int i = 0; i < velocidadPulsacion; i++)
{
botonAuno = 1;
delay(velocidadPulsacion);
botonAdos = 0;
if (keypad.getKey() == 'A')
{
botonAdos = 1;
botonAuno = 0;
break;
}
}
if (botonAuno == 1)
{
digitalWrite(ledrojo, HIGH);
lcd.clear();
switch (menuUno)
{
case INICIO:
menuUno = LOGO;
break;
case LOGO:
menuUno = TITLE;
break;
case TITLE:
menuUno = GAMEPLAY;
break;
case GAMEPLAY:
menuUno = ENDING;
break;
case ENDING:
menuUno = INICIO;
break;
default:
break;
}
}
if (botonAdos == 1)
{
digitalWrite(ledrojo, LOW);
lcd.clear();
switch (menuUno)
{
case INICIO:
menuUno = ENDING;
break;
case LOGO:
menuUno = INICIO;
break;
case TITLE:
menuUno = LOGO;
break;
case GAMEPLAY:
menuUno = TITLE;
break;
case ENDING:
menuUno = GAMEPLAY;
break;
default:
break;
}
}
}
}