#include <LiquidCrystal_I2C.h>
#include <Wire.h>
const byte Btn1 = 2;
const byte Btn2 = 3;
const byte LED1 = 12;
const byte LED2 = 11;
volatile bool ISR1 = false;
volatile bool ISR2 = false;
const byte VPOT1 = A0;
const byte VPOT2 = A1;
const float Vref1 = 5.0;
const float Vref2 = 2.5;
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(Btn1, INPUT_PULLUP);
pinMode(Btn2, INPUT_PULLUP);
Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(Btn1),ISR11,CHANGE);
attachInterrupt(digitalPinToInterrupt(Btn2),ISR12,CHANGE);
}
void loop() {
//check intterupt 1
if(ISR1){
Serial.println("Interrupt 1 detected wait 5 Seconds");
digitalWrite(LED1, HIGH);
lcd.clear(); // clear display
lcd.setCursor(4, 0); // move cursor to (4, 0)
lcd.print("INTERRUPT 1"); // 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();
}
//check intterupt 2
if(ISR2){
Serial.println("Interrupt 2 detected wait 7 Seconds");
digitalWrite(LED2, HIGH);
lcd.clear(); // clear display
lcd.setCursor(4, 0); // move cursor to (4, 0)
lcd.print("INTERRUPT 2"); // print message at (4, 0)
lcd.setCursor(4, 1); // move cursor to (4, 1)
lcd.print("7 Seconds"); // print message at (4, 1)
delay(7000); // display the above for twelve second
digitalWrite(LED2, LOW);
ISR2 = false;
lcd.clear();
}
POT1();
POT2();
}
void POT1(){
int s = analogRead(VPOT1);
float vol1 = (s * Vref1/1023);
//float voltage = map(analog_value, 0, 1023, 0 , 5);
char analog_string1[7];
dtostrf(vol1, 5, 2, analog_string1);
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("Volts:"); // print message at (0, 0)
lcd.print(analog_string1);
lcd.print("V,FS");
Serial.println("Full scale Voltage = " + String(analog_string1) + "V" + " and resolution = " + s);
delay(100);
}
void POT2(){
int c = analogRead(VPOT2);
int c1 = c/2;
float vol2 = (c1 * Vref2/511);
//float voltage = map(analog_value, 0, 1023, 0 , 5);
char analog_string2[7];
dtostrf(vol2, 5, 2, analog_string2);
lcd.setCursor(0, 1); // move cursor to (0, 0)
lcd.print("Volts:"); // print message at (0, 0)
lcd.print(analog_string2);
lcd.print("V,HS");
Serial.println("Half scale Voltage = " + String(analog_string2) + "V" + " and resolution = " + c1);
delay(100);
}
void ISR11(){
ISR1 = true;
}
void ISR12(){
ISR2 = true;
}