#include <LiquidCrystal_I2C.h>
#include <Wire.h>
const byte Btn1 = 2;
const byte LED1 = 12;
const byte Bzr1 = 5;
volatile bool ISR1 = false;
const byte VPOT = A0;
const float Vref = 5.0;
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
void setup() {
pinMode(LED1, OUTPUT);
pinMode(Bzr1, OUTPUT);
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(Btn1, INPUT_PULLUP);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(Btn1),ISR11,RISING);
}
void loop() {
//check intterupt 2
if(ISR1){
Serial.println("Interrupt detected wait 5 Seconds");
digitalWrite(LED1, HIGH);
lcd.clear(); // clear display
lcd.setCursor(4, 0); // move cursor to (4, 0)
lcd.print("INTERRUPT"); // print message at (4, 0)
lcd.setCursor(4, 1); // move cursor to (4, 1)
lcd.print("5 Seconds"); // print message at (4, 1)
delay(5000); // display the above for twelve second
digitalWrite(LED1, LOW);
ISR1 = false;
lcd.clear();
}
POT1();
}
void POT1(){
int s = analogRead(VPOT);
float vol = (s * Vref/1023);
//float voltage = map(analog_value, 0, 1023, 0 , 5);
char analog_string[7];
dtostrf(vol, 5, 2, analog_string);
lcd.clear();
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("Volts:"); // print message at (0, 0)
lcd.print(analog_string);
lcd.print("V");
lcd.setCursor(0, 1); // move cursor to (0, 0)
lcd.print("Reso:");
lcd.print(s);
Serial.println("Voltage =" + String(analog_string) + "V" + " and resolution =" + s);
delay(100);
}
void ISR11(){
ISR1 = true;
}