// https://forum.arduino.cc/t/using-two-button-loop/987314

#include <LiquidCrystal.h>

const int pinOn = A0;  // 10 conflict
const int pinOff = A1;  // 9 conflict
const int pinledOn = 13;
const int pinledOff = 6;  // 8 conflict 


LiquidCrystal lcd(12, 11,    10, 9, 8, 7);
// LiquidCrystal lcd(12,11,         5, 4, 3, 2);

int estaon = 0;
int estaoff = 0;

int inicioOn = 0;
int inicioOff = 0;

int switchVar = 0;
 
void setup() {
  Serial.begin (9600);
  Serial.println("hello two button loop");

  pinMode(pinOn, INPUT);
  pinMode(pinOff, INPUT);

  pinMode(pinledOn, OUTPUT);
  pinMode(pinledOff, OUTPUT);
  lcd.begin(16,2);
}

void Encendido() { Serial.println("Encendidox");}
void Apagado() { Serial.println("Apagadox");}

// originals. edit if you have 5.5 hours to test this

void EncendidoOriginal(){
  for (int contador = 0; contador < 1000; contador++){
    
    digitalWrite(pinledOn, HIGH); // Enciende el LED
    lcd.setCursor(0,0);
    lcd.print("    Filling  ");
    lcd.setCursor(0,0);
    lcd.setCursor(0,1);	
    lcd.print("               ");
    lcd.setCursor(0,1);  
    delay(1777);
    digitalWrite(pinledOn, LOW);  
    lcd.setCursor(0,0);	
    lcd.print("  Bottle Ready");	
    lcd.setCursor(0,0);
    lcd.setCursor(0,1);	
    lcd.print("Cantidad: "+String(contador+1));	
    lcd.setCursor(0,1);
    delay(1777);  
  }
    
}

void ApagadoxOriginal() {
  digitalWrite(pinledOff, HIGH);
  digitalWrite(pinledOn, LOW); 
  lcd.setCursor(0,0);
  lcd.print("      Bye     ");
  lcd.setCursor(0,0);
  lcd.setCursor(0,1);
  lcd.print("     OFF    ");
  lcd.setCursor(0,1);
}

void loop() {
  estaon = digitalRead(pinOn);
  estaoff = digitalRead(pinOff);
 
  // WAS THE ON BUTTON PUSHED?
  	if (estaon == LOW && inicioOn == HIGH) {
    	switchVar = 1;

    }
  
  // WAS THE OFF BUTTON PUSHED?
  	else if (estaoff == LOW && inicioOff == HIGH) {
    	switchVar = 2;
    
  	}
inicioOn = estaon;  
inicioOff = estaoff;
  
  	switch (switchVar)
  	{
    	case 1:
    		Encendido ();
    		break;

   		case 2:
    		Apagado ();
    		break;
  	}
}