#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define boton 10
#define clk 5
#define dt 6
#define ledrojo 13
LiquidCrystal_I2C lcd(0x27, 16, 2);
int contadorboton = 0;
int ventana = 0;
int rtnumero = 0;
int contador = 0;
int estado_clk_old =0;
enum Maquinamenu { SUMA = 0, INICIO, EMPEZAR, COLOR} Maquinamenu;
void setup() {
pinMode(ledrojo, OUTPUT);
pinMode(boton, INPUT_PULLUP);
Serial.begin(9600);
lcd.init();
lcd.backlight();
}
void loop() {
//lcd.clear();
//lcd.setCursor(5, 0);
//lcd.print("HOLA!!");
//lcd.setCursor(0, 1);
//lcd.print("Gira el encoder");
/*
int estado_clk = digitalRead (clk);
int estado_dt = digitalRead (dt);
if (estado_clk_old == HIGH && estado_clk == LOW) {
if (estado_dt == LOW){
contador--;
}else{
contador++;
if (contador == 4) {
contador = 0;
ventana = 4;
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Contando: ");
lcd.print(contador);
delay(1);
}
}
estado_clk_old = estado_clk;
*/
int estadoboton = digitalRead(boton);
switch (ventana)
{
case SUMA: {
if (estadoboton == 0) {
contadorboton++;
while (digitalRead(boton) == 0){}
Serial.print(contadorboton);
if (contadorboton == 3){
contadorboton = 0;
ventana = INICIO;
}
lcd.setCursor(0, 0);
lcd.print("llega a 5: ");
lcd.print(contadorboton);
}
}
break;
case INICIO: {
if (estadoboton == 0)
ventana = EMPEZAR;
while (digitalRead(boton) == 0){}
lcd.setCursor(0, 0);
lcd.print("INICIO!!! ");
}
break;
case EMPEZAR: {
if (estadoboton == 0)
ventana = COLOR;
while (digitalRead(boton) == 0){}
lcd.setCursor(0, 0);
lcd.print("EMPEZAR!!!!!! ");
}
break;
case COLOR: {
if (estadoboton == 0)
ventana = SUMA;
while (digitalRead(boton) == 0){}
lcd.setCursor(0, 0);
lcd.print("Modifica el color");
}
break;
default: break;
}
}