#include <Wire.h>  // Comes with Arduino IDE
// Get the LCD I2C Library here: 
// https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move any other LCD libraries to another folder or delete them
// See Library "Docs" folder for possible commands etc.
#include <LiquidCrystal_I2C.h>
// set the LCD address to 0x27 for a 20 chars 4 line display
// you may need to run an I2C address program to find the address for your LCD
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
//LiquidCrystal_I2C lcd(0x27, 4, 5, 6, 0, 1, 2, 3, 7, NEGATIVE);  // Set the LCD I2C address
//LiquidCrystal_I2C lcd(0x27, 4, 5, 6, 0, 1, 2, 3, 7, POSITIVE);  // Set the LCD I2C address
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity

//Define Memory Locations

      byte Timer0 = 100;  // sets memory and its default start up value, time is in miliseconds 

//Define port pins
      int Button_Down = 10;
      
      int Button_Enter = 11;

      int Button_Up = 12;

       int Spot_Out = 13;
       
void setup() {
  // put your setup code here, to run once:

//setup port pins

 pinMode(Button_Down, INPUT_PULLUP);

 pinMode(Button_Up, INPUT_PULLUP);

 pinMode(Button_Enter, INPUT_PULLUP);

  pinMode(Spot_Out, OUTPUT);

  
  lcd.begin(20,4);         // initialize the lcd for 20 chars 4 lines

// NOTE: Cursor Position: CHAR, LINE) start at 0  
  lcd.setCursor(5,0); //Start at character 5 on line 0
  lcd.print("18650 Spot");
  delay(500);
  lcd.setCursor(7,1);
  lcd.print("Welder");
  delay(500);  
  lcd.setCursor(3,2);
  lcd.print("EV-North.co.uk");                                     
  delay(1500); 
  lcd.clear();
  lcd.setCursor(3,0);
  lcd.print("EV-North.co.uk");

  delay(1000);
  lcd.setCursor(5,1);
  lcd.print("Spot Timer:");
  lcd.setCursor(0,2);
  lcd.print("O-down");
  lcd.setCursor(16,2);
  lcd.print("Up-O");
  lcd.setCursor(7,3);
  lcd.print("O-Enter");
}

void loop() {
//======================================================================
// Button Down code
if (digitalRead(Button_Down) == LOW){
  delay(200);
  Timer0 = Timer0 -1;
  lcd.setCursor(0,2);
  lcd.print("Pressed");
    
  }

if (digitalRead(Button_Down) == HIGH){
  lcd.setCursor(0,2);
  lcd.print("O-Down ");
    
  }
//======================================================================
// Button Enter code
if (digitalRead(Button_Enter) == LOW){
  lcd.setCursor(7,3);
  lcd.print("Pressed");

    digitalWrite(Spot_Out, HIGH);   // Spot weld on
      lcd.setCursor(0,3);
       lcd.print("ON ");
    delay (Timer0);

    digitalWrite(Spot_Out, LOW);    // Spot weld off
     lcd.setCursor(0,3);
       lcd.print("OFF");
               lcd.setCursor(7,3);
              lcd.print("O-HOLD ");      
           delay (1000);            // do a delay to help prevent a double trigger

  }

if (digitalRead(Button_Enter) == HIGH){
  lcd.setCursor(7,3);
  lcd.print("O-Enter");
    
  }
//======================================================================
// Button Up code
if (digitalRead(Button_Up) == LOW){
  delay(200);
  Timer0 = Timer0 +1;
  lcd.setCursor(13,2);
  lcd.print("Pressed");
    
  }

if (digitalRead(Button_Up) == HIGH){
  lcd.setCursor(13,2);
  lcd.print("   O-Up");
    
  }

//======================================================================
  // put your main code here, to run repeatedly:
    lcd.setCursor(17,1);
  lcd.print("   ");
    lcd.setCursor(17,1);
  lcd.print(Timer0);

}
