volatile int counter = 0;
void setup() {
Serial.begin(9600);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
PCICR |= B00000100; // Enable interrupts on PD port
PCMSK2 |= B00110000; // Trigger interrupts on pins D4 and D5
}
void loop() {
Serial.print("The counter is now at: ");
Serial.println(counter);
delay(1000);
}
ISR (PCINT2_vect) {
if (PIND & B00010000) {
counter++;
}
else if (PIND & B00100000) {
counter--;
}
}