int pulsanteA=10;
int pulsanteB=11;
int pulsanteC=12;
int pulsanteD=13;
int releGroup4=6;
int releGroup3=7;
int releGroup2=8;
int releGroup1=9;

int group=1;
int offset=0;
int groupReleIndex[4]={
  0, 0, 0, 0,};
int releIndex=0;
int rele[30]={
  22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,
  37,38,39,40,41};

bool ONS1=false, ONS2=false, ONS3=false, ONS4=false; 
bool resetActive=false, startReset=false;

void setup() {
Serial.begin(9600);

  pinMode(pulsanteB, INPUT_PULLUP);
  pinMode(pulsanteA, INPUT_PULLUP);
  pinMode(pulsanteC, INPUT_PULLUP);
  pinMode(pulsanteD, INPUT_PULLUP);
  pinMode(releGroup1, OUTPUT);
  pinMode(releGroup2, OUTPUT);
  pinMode(releGroup3, OUTPUT);
  pinMode(releGroup4, OUTPUT);
 
  for(int pin=0; pin<30; pin++){
  pinMode(rele[pin], OUTPUT);
  }
}

void loop() {

  if(!digitalRead(pulsanteA) and !ONS1){
    ONS1=true;
    groupReleIndex[group-1]=releIndex;
    group++;
    releIndex=groupReleIndex[group-1];
    offset+=5;
    if(group>4){
    group=4;
    offset=15;
    }
    delay(200);
  }
  if(digitalRead(pulsanteA)){
    ONS1=false;
  }

    if(!digitalRead(pulsanteB) and !ONS2){
    ONS2=true;
    groupReleIndex[group-1]=releIndex;
    group--;
    releIndex=groupReleIndex[group-1];
    offset-=5;
    if(group<1){
    group=1;
    releIndex=groupReleIndex[group-1];
    offset=0;
    }
    delay(200);
  }
  if(digitalRead(pulsanteB)){
    ONS2=false;
  }

  if(!digitalRead(pulsanteC) and !ONS3){
    ONS3=true;
    if(releIndex>4){
      releIndex=4;
    }
    digitalWrite(rele[releIndex+offset], HIGH);
    releIndex++;
    delay(200);
  }
  if(digitalRead(pulsanteC)){
    ONS3=false;
  }

  if(!digitalRead(pulsanteD) and !ONS4){
    ONS4=true;
    releIndex--;
    if(releIndex<0){
      releIndex=0;
    }
    digitalWrite(rele[releIndex+offset], LOW);
  }
  if(digitalRead(pulsanteD)){
    ONS4=false;
  }
  switch (group) {
    case 1:
      digitalWrite(releGroup1, HIGH);
      digitalWrite(releGroup2, LOW);
      digitalWrite(releGroup3, LOW);
      digitalWrite(releGroup4, LOW);
    break;

    case 2:
      digitalWrite(releGroup1, LOW);
      digitalWrite(releGroup2, HIGH);
      digitalWrite(releGroup3, LOW);
      digitalWrite(releGroup4, LOW);
    break;

    case 3:
      digitalWrite(releGroup1, LOW);
      digitalWrite(releGroup2, LOW);
      digitalWrite(releGroup3, HIGH);
      digitalWrite(releGroup4, LOW);
    break;

    case 4:
      digitalWrite(releGroup1, LOW);
      digitalWrite(releGroup2, LOW);
      digitalWrite(releGroup3, LOW);
      digitalWrite(releGroup4, HIGH);
    break;
    
  }
    }

NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module