/* example interrupt pulse counter
*/

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,20,4); 

int enable = 27; 
int pulse = 0; 
int red = 4;
int green = 2;


void count() 
{ 
pulse++; 
} 

void setup() 
{
 lcd.init();                      // initialize the lcd
 lcd.backlight();
 pinMode(red, OUTPUT);
 pinMode(green, OUTPUT); 
 Serial.begin(112500); 
 pinMode(14, INPUT_PULLUP);
 pinMode(27, INPUT_PULLUP); 
 attachInterrupt(14, count, FALLING); 
} 
 
void loop() 
{ 
  if (digitalRead(enable) != 0)
  {
    
    digitalWrite(green, HIGH);
    digitalWrite(red, LOW);
    interrupts(); 
    Serial.print("Pulses:"); 
    Serial.println(pulse);
    lcd.setCursor(2,0);
    lcd.print("Pulse: ");
    lcd.setCursor(2,1);
    lcd.print(pulse);
    delay(10);
  }

  if (digitalRead(enable) == 0)
  { 
    //noInterrupts();
    digitalWrite(green, LOW);
    digitalWrite(red, HIGH);
    delay(10);
    pulse = 0;
    delay(100);
    lcd.clear();
  }
 
}