#include <TimerOne.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);

const int ledPin = 5;  // the pin with a LED
const int  buttonPin1 = 6;
const int  buttonPin2 = 5;
int buttonState1 = 0;         // current state of the button
int lastButtonState1 = 0;     // previous state of the button
int buttonState2 = 0;         // current state of the button
int lastButtonState2 = 0;     // previous state of the button

void setup(void)
{  
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  Timer1.initialize(1000000);
  Timer1.attachInterrupt(blinkLED);
  lcd.begin(16, 2);
  lcd.setBacklight(1);
  Serial.begin(9600);
  }

int ledState = LOW;
volatile unsigned long blinkCount = 10;


void blinkLED()
{
buttonState1 = digitalRead(buttonPin1);
  if (buttonState1==1)  {
    Timer1.attachInterrupt(blinkLED);
    blinkCount = blinkCount - 1;
    digitalWrite(ledState, HIGH);
  } 
  if (blinkCount==1){
  blinkCount=0;
  //blinkCount = blinkCount;
  Timer1.stop();
  }
  if (blinkCount==0 && buttonState1==1){
  Timer1.attachInterrupt(blinkLED);
    blinkCount = blinkCount - 1;  
  }
  //else {
  //blinkCount = 10;
  //}
  if (blinkCount==0 && buttonState1==0){
    Timer1.stop();
  }
  digitalWrite(buttonPin1, buttonState1);
}

void loop(void)
{
  //Timer1.start();
  unsigned long blinkCopy;  // holds a copy of the blinkCount
  noInterrupts();
  blinkCopy = blinkCount;
  interrupts();
 //Serial.print("blinkCount = ");
  //Serial.println(blinkCopy);
  lcd.setCursor(0,0);
  lcd.print("Count");
  lcd.setCursor(0,1);
  lcd.print(blinkCopy);
  delay(100);
}