#include <avr/io.h>
#include <avr/interrupt.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(B00100111, 16, 2);
ISR(PCINT2_vect) {
//inputs are active low
uint8_t pd = ~PIND;
if (pd & B00000100)//Specify the pc interrupt on pin 2
PORTB |= 1 << PB1;
}
void setup() {
DDRD &= ~((1 << PD2)); //PortD as input
PORTD = (1 << PD2); //use pullup resistor on PinD2
// Enable pin change interrupts
PCICR = 1 << PCIE2;//enable pin change interrupt bank 2
PCMSK2 = (1 << PCINT18);;//enable pin change interrupt on PCINT18 (PinD2)
sei();// Set global interrupt flag
//set up the LCD's number of columns and rows:
lcd.begin(16, 2);
//Print a message to the LCD.
lcd.print("Hello!");
}
int main() {
init();
setup();
for (;;)
{
//set the cursor to column 0, line 1
//(note: line 1 is the second row):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
}