Arduino Nano / One pin activates all functions

Hi guys,
I need your help please. I just started w/ Arduino a few hours ago and I cant figure out, what I am doing wrong here.
I have 4 inputs and I have copied this Arduino Playground - PcInt to enable interrupt process on any pin.

PCINT code ......

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(A0, OUTPUT);
  pinMode(A1, OUTPUT);
  pinMode(A2, OUTPUT);
  pinMode(A3, OUTPUT);

  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(10, INPUT_PULLUP);
  pinMode(11, INPUT_PULLUP);

  PCattachInterrupt(8, input8, CHANGE);
  PCattachInterrupt(9, input9, CHANGE);
  PCattachInterrupt(10, input10, CHANGE);
  PCattachInterrupt(11, input11, CHANGE);

  
  Serial.begin(115200);
}

bool status = true;
int led_press[4];

// the loop function runs over and over again forever
void loop() {
  for(int i = 0; i < 4; i++){
    Serial.print(led_press[i]);  
  }
  Serial.print("\n");
  delay(1000);
}

void input8(){
  led_press[0] = 1;
}
void input9(){
  led_press[1] = 2;
}
void input10(){
  led_press[2] = 3;
}
void input11(){
  led_press[3] = 4;
}

What is happening is that if I activate pin 8, all functions from input8-11 activate. So if I activate pin 8, led_press is {1, 2, 3, 4} instead of {1, 0, 0, 0}.
Any suggestions? It might be just a stupid mistake I made, but I cannot see it.
THANKS!

Pin change interrupts apply to a group of I/O pins. When the interrupt fires your ISR needs to check which of the pins caused it.

Also I think a single ISR is all that is needed for a group of pins. I say "I think" because I have never used the PCattachInterrupt() function.

...R

The code that you're not displaying, are you sure that you got that correctly? I just compiled and ran (currently still running) the code from the link and it works fine.

Thanks for answers guys,

Robin2:
Pin change interrupts apply to a group of I/O pins. When the interrupt fires your ISR needs to check which of the pins caused it.

Also I think a single ISR is all that is needed for a group of pins. I say "I think" because I have never used the PCattachInterrupt() function.

...R

I haven't heard about ISR, will check/try it.. anyway THANKS!

DKWatson:
The code that you're not displaying, are you sure that you got that correctly? I just compiled and ran (currently still running) the code from the link and it works fine.

#include "pins_arduino.h"

volatile uint8_t *port_to_pcmask[] = {
  &PCMSK0,
  &PCMSK1,
  &PCMSK2
};

static int PCintMode[24];

typedef void (*voidFuncPtr)(void);

volatile static voidFuncPtr PCintFunc[24] = { 
  NULL };

volatile static uint8_t PCintLast[3];

void PCattachInterrupt(uint8_t pin, void (*userFunc)(void), int mode) {
  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  uint8_t slot;
  volatile uint8_t *pcmask;

  // map pin to PCIR register
  if (port == NOT_A_PORT) {
    return;
  } 
  else {
    port -= 2;
    pcmask = port_to_pcmask[port];
  }

// -- Fix by Baziki. In the original sources it was a little bug, which cause analog ports to work incorrectly.
  if (port == 1) {
     slot = port * 8 + (pin - 14);
  }
  else {
     slot = port * 8 + (pin % 8);
  }
// --Fix end
  PCintMode[slot] = mode;
  PCintFunc[slot] = userFunc;
  // set the mask
  *pcmask |= bit;
  // enable the interrupt
  PCICR |= 0x01 << port;
}

void PCdetachInterrupt(uint8_t pin) {
  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  volatile uint8_t *pcmask;

  // map pin to PCIR register
  if (port == NOT_A_PORT) {
    return;
  } 
  else {
    port -= 2;
    pcmask = port_to_pcmask[port];
  }

  // disable the mask.
  *pcmask &= ~bit;
  // if that's the last one, disable the interrupt.
  if (*pcmask == 0) {
    PCICR &= ~(0x01 << port);
  }
}

// common code for isr handler. "port" is the PCINT number.
// there isn't really a good way to back-map ports and masks to pins.
static void PCint(uint8_t port) {
  uint8_t bit;
  uint8_t curr;
  uint8_t mask;
  uint8_t pin;

  // get the pin states for the indicated port.
  curr = *portInputRegister(port+2);
  mask = curr ^ PCintLast[port];
  PCintLast[port] = curr;
  // mask is pins that have changed. screen out non pcint pins.
  if ((mask &= *port_to_pcmask[port]) == 0) {
    return;
  }
  // mask is pcint pins that have changed.
  for (uint8_t i=0; i < 8; i++) {
    bit = 0x01 << i;
    if (bit & mask) {
      pin = port * 8 + i;
      // Trigger interrupt if mode is CHANGE, or if mode is RISING and
      // the bit is currently high, or if mode is FALLING and bit is low.
      if ((PCintMode[pin] == CHANGE
          || ((PCintMode[pin] == RISING) && (curr & bit))
          || ((PCintMode[pin] == FALLING) && !(curr & bit)))
          && (PCintFunc[pin] != NULL)) {
        PCintFunc[pin]();
      }
    }
  }
}

SIGNAL(PCINT0_vect) {
  PCint(0);
}
SIGNAL(PCINT1_vect) {
  PCint(1);
}
SIGNAL(PCINT2_vect) {
  PCint(2);
}

void setup() {

@Robin2, the code in the reference link seems to have taken care of the pin resolution, allowing for 24 function pointers. Which is pretty good as there are only 20 pin interrupts on the 328p.

DKWatson:
The code that you're not displaying, are you sure that you got that correctly? I just compiled and ran (currently still running) the code from the link and it works fine.

I tried to copy and paste code once again and it is still not working properly. Each pin activates all functions..

How attached are you to your chosen solution?

Try this one.

#include <EnableInterrupt.h>

void setup()
{
    // initialize digital pin LED_BUILTIN as an output.
    pinMode(A0, OUTPUT);
    pinMode(A1, OUTPUT);
    pinMode(A2, OUTPUT);
    pinMode(A3, OUTPUT);

    pinMode(8, INPUT_PULLUP);
    pinMode(9, INPUT_PULLUP);
    pinMode(10, INPUT_PULLUP);
    pinMode(11, INPUT_PULLUP);

    enableInterrupt(8, input8, CHANGE);
    enableInterrupt(9, input9, CHANGE);
    enableInterrupt(10, input10, CHANGE);
    enableInterrupt(11, input11, CHANGE);

    Serial.begin(115200);
}

bool status = true;
int led_press[4];

// the loop function runs over and over again forever
void loop()
{
    for (int i = 0; i < 4; i++)
    {
        Serial.print(led_press[i]);
    }
    Serial.print("\n");
    delay(1000);
}

void input8()
{
    led_press[0] = 1;
}
void input9()
{
    led_press[1] = 2;
}
void input10()
{
    led_press[2] = 3;
}
void input11()
{
    led_press[3] = 4;
}

@DKWatson
It is working! Thank you so much!
Have a nice day.

DKWatson:
@Robin2, the code in the reference link

Sorry ... what reference link?

...R