I just tested proper code with some changes:
#include <PinChangeInterrupt.h>
const uint8_t buttonPin = 11;
volatile bool buttonPressed = false;
void buttonISR() {
buttonPressed = true;
}
void loop() {
if (buttonPressed) {
delay(20);
buttonPressed = false;
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
}
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
attachPCINT(digitalPinToPCINT(buttonPin), buttonISR, RISING);
pinMode(LED_BUILTIN, OUTPUT);
}
And with attachPCINT(digitalPinToPCINT(buttonPin), buttonISR, RISING);
it works flawlessly. Only difference is that digitalPinToPCINT
(as every example for PinChangeInterrupt library tries to suggest).
You also tried attachInterrupt + digitalPinToInterrupt with the pin 11, but Arduino Uno has only two external interrupt capable pins D2 and D3. So it couldn't work with D11. It also depends on MCU (see attachInterrupt() reference).
The PCINT is more or less related to the old AVRs like Atmega328 or Atmega2560. And PCINT in Atmega2560 isn't available on all port (it uses ISR per port and it has many ports.
If the proteus simulator is the cause, you can also ommit the ISR (as you are not doing anything big here) and just poll the pin:
const uint8_t buttonPin = 11;
bool buttonPressed = false;
void loop() {
bool pinHigh = (digitalRead(buttonPin) == HIGH);
if (pinHigh && buttonPressed) { // button released
delay(20);
buttonPressed = false;
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
} else if (!pinHigh && !buttonPressed) {
buttonPressed = true;
}
}
void setup() {
pinMode(buttonPin, INPUT_PULLUP);
pinMode(LED_BUILTIN, OUTPUT);
}
attachInterrupt(digitalPinToInterrupt(buttonPin), buttonISR, FALLING)
also does not work