#include <LiquidCrystal_I2C.h>
#include <Wire.h>
const byte Btn1 = 2;
const byte Btn2 = 3;
const byte LED1 = 4;
const byte Bzr1 = 5;
const byte POT11 = A3;
const byte POT21 = A2;
volatile bool ISR11 = false;
volatile bool ISR12 = false;
const float Voltage_Devider_Ratio = 0.5;
const float Reference_Voltage = 5.0;
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
void setup() {
// put your setup code here, to run once:
lcd.init(); // initialize the lcd
lcd.backlight();
pinMode(LED1, OUTPUT);
pinMode(Bzr1, OUTPUT);
pinMode (Btn1, INPUT_PULLUP);
pinMode(Btn2, INPUT_PULLUP);
// Enable PCIE2 Bit3 = 1 (Port D)
PCICR |= B00000100;
// Enable PCINT18 & PCINT19 (Pins D2 & D3)
PCMSK2 |= B00001100;
}
void loop() {
//check intterupt 1
if(ISR11){
digitalWrite(LED1, HIGH);
lcd.clear(); // clear display
lcd.setCursor(2, 0); // move cursor to (2, 0)
lcd.print("LED ISR1 ON"); // print message at (2, 0)
lcd.setCursor(2, 1); // move cursor to (2, 1)
lcd.print("8 Seconds"); // print message at (2, 1)
delay(8000); // display the above for two second
digitalWrite(LED1, LOW);
ISR11 = false;
}
//check intterupt 2
if(ISR12){
digitalWrite(Bzr1, HIGH);
lcd.clear(); // clear display
lcd.setCursor(2, 0); // move cursor to (2, 0)
lcd.print("BUZZER ISR2 ON"); // print message at (2, 0)
lcd.setCursor(2, 1); // move cursor to (2, 1)
lcd.print("7 Seconds"); // print message at (2, 1)
delay(7000); // display the above for two second
digitalWrite(Bzr1, LOW);
ISR12 = false;
}
// put your main code here, to run repeatedly:
POT1();
POT2();
}
void POT1(){
int analog_value = analogRead(POT11);
float voltage = (analog_value * Reference_Voltage/1023) * Voltage_Devider_Ratio;
// maximun value is 2.5 V
//float voltage = map(analog_value, 0, 1023, 0 , 5);
char analog_string[7];
dtostrf(voltage, 5, 3, analog_string);
//lcd.clear(); // clear display
lcd.setCursor(0, 0); // move cursor to (0, 0)
lcd.print("POT1:"); // print message at (0, 0)
lcd.print(analog_string);
lcd.print("V, ");
lcd.print(analog_value);
delay(100); // display the above for two second
}
void POT2(){
int analog_value = analogRead(POT21);
float voltage = (analog_value * Reference_Voltage/1023);
// maximun value is 2.5 V
//float voltage = map(analog_value, 0, 1023, 0 , 5);
char analog_string[7];
dtostrf(voltage, 5, 3, analog_string);
//lcd.clear(); // clear display
lcd.setCursor(0, 1); // move cursor to (0, 1)
lcd.print("POT2:"); // print message at (0, 1)
lcd.print(analog_string);
lcd.print("V, ");
lcd.print(analog_value);
delay(100);
}
ISR (PCINT2_vect)
{
// Port D Interrupt occured
if (digitalRead(Btn1) == LOW) {
ISR11 = true;
}
if (digitalRead(Btn2) == LOW) {
ISR12 = true;
}
}