//Program Controller 4 Relee cu array

const int Releu_PIN1 = 12;
const int Releu_PIN2 = 11;
const int Releu_PIN3 = 9;
const int Releu_PIN4 = 8;

// int stare_PIN1 = 1;
// int stare_PIN2 = 1;
// int stare_PIN3 = 1;
// int stare_PIN4 = 1;


int nrProg = 0;
int Timp_delay = 500;

void setup() {
pinMode(Releu_PIN1, OUTPUT);
pinMode(Releu_PIN2, OUTPUT);
pinMode(Releu_PIN3, OUTPUT);
pinMode(Releu_PIN4, OUTPUT);

digitalWrite(Releu_PIN1, HIGH);
digitalWrite(Releu_PIN2, HIGH);
digitalWrite(Releu_PIN3, HIGH);
digitalWrite(Releu_PIN4, HIGH);

// digitalWrite(Releu_PIN1, stare_PIN1);
// digitalWrite(Releu_PIN2, stare_PIN2);
// digitalWrite(Releu_PIN3, stare_PIN3);
// digitalWrite(Releu_PIN4, stare_PIN4);
//pinMode(LED_BUILTIN, OUTPUT); // set the digital pin as output
Serial.begin(9600);
 Serial.println ("Introduceti nr. programului:");
 while(nrProg == 0){
    if(Serial.available()>0){
    //String comanda = Serial.readStringUntil('\n'); // citeste  until meet newline character
    nrProg = Serial.read();
    }
 }
Serial.print("Se executa Programul ");
Serial.write(nrProg);
Serial.println(" !");

}

void loop() {
  int stare_PIN1[4] = {1,1,1,1};
  int stare_PIN2[4] = {1,1,1,1};
  int stare_PIN3[4] = {1,1,1,1};
  int stare_PIN4[4] = {1,1,1,1};
  //int stare_PIN1[4];// = {1,1,1,1};
  //int stare_PIN2[4];// = {1,1,1,1};
  //int stare_PIN3[4];// = {1,1,1,1};
  //int stare_PIN4[4];// = {1,1,1,1};
  //int stare_PIN1_1 = 1;
  //int stare_PIN2_1 = 1;
  //int stare_PIN3_1 = 1;
  //int stare_PIN4_1 = 1;
  //int stare_PIN1_2 = 1;
  //int stare_PIN2_2 = 1;
  //int stare_PIN3_2 = 1;
  //int stare_PIN4_2 = 1;
  //int stare_PIN1_3 = 1;
  //int stare_PIN2_3 = 1;
  //int stare_PIN3_3 = 1;
  //int stare_PIN4_3 = 1;
  //int stare_PIN1_4 = 1;
  //int stare_PIN2_4 = 1;
  //int stare_PIN3_4 = 1;
  //int stare_PIN4_4 = 1;
  
  switch (nrProg){
     case '1':
            stare_PIN1[0]=0;// {0,1,1,1};
            stare_PIN2[1]=0;// {1,0,1,1};
            stare_PIN3[2]=0;// {1,1,0,1};
            stare_PIN4[3]=0;// {1,1,1,0};
            //stare_PIN1_1 = 0;
            //stare_PIN3_1 = 1;
            //stare_PIN4_1 = 1;
            //stare_PIN1_2 = 1;
            //stare_PIN2_2 = 0;
            //stare_PIN3_2 = 1;
            //stare_PIN4_2 = 1;
            //stare_PIN1_3 = 1;
            //stare_PIN2_3 = 1;
            //stare_PIN3_3 = 0;
            //stare_PIN4_3 = 1;
            //stare_PIN1_4 = 1; 
            //stare_PIN2_4 = 1;
            //stare_PIN3_4 = 1;
            //stare_PIN4_4 = 0;
     break;

     case '2':
            stare_PIN1[0]=0;// {0,1,0,1};
            stare_PIN1[2]=0;
            stare_PIN2[1]=0;// {1,0,1,0};
            stare_PIN2[3]=0;
            stare_PIN3[0]=0;// {0,1,0,1};
            stare_PIN3[2]=0;
            stare_PIN4[1]=0;// {1,0,1,0};
            stare_PIN4[3]=0;
            //stare_PIN1_1 = 0;
            //stare_PIN2_1 = 1;
            //stare_PIN3_1 = 0;
            //stare_PIN4_1 = 1;
            //stare_PIN1_2 = 1;
            //stare_PIN2_2 = 0;
            //stare_PIN3_2 = 1;
            //stare_PIN4_2 = 0;
            //stare_PIN1_3 = 0;
            //stare_PIN2_3 = 1;
            //stare_PIN3_3 = 0;
            //stare_PIN4_3 = 1;
            //stare_PIN1_4 = 1;
            //stare_PIN2_4 = 0;
            //stare_PIN3_4 = 1;
            //stare_PIN4_4 = 0;
     break;

     case '3':
            stare_PIN1[0]=0;// {0,0,1,1};
            stare_PIN1[1]=0;
            stare_PIN2[2]=0;// {1,1,0,0};
            stare_PIN2[3]=0;
            stare_PIN3[0]=0;// {0,0,1,1};
            stare_PIN3[1]=0;
            stare_PIN4[2]=0;// {1,1,0,0};
            stare_PIN4[3]=0;
            //stare_PIN1_1 = 0;
            //stare_PIN2_1 = 0;
            //stare_PIN3_1 = 1;
            //stare_PIN4_1 = 1;
            //stare_PIN1_2 = 1;
            //stare_PIN2_2 = 1;
            //stare_PIN3_2 = 0;
            //stare_PIN4_2 = 0;
            //stare_PIN1_3 = 0;
            //stare_PIN2_3 = 0;
            //stare_PIN3_3 = 1;
            //stare_PIN4_3 = 1;
            //stare_PIN1_4 = 1;
            //stare_PIN2_4 = 1;
            //stare_PIN3_4 = 0;
            //stare_PIN4_4 = 0;
    break;

    case '4':
            stare_PIN1[0]=0;// {0,0,0,0};
            stare_PIN1[1]=0;
            stare_PIN1[2]=0;
            stare_PIN1[3]=0;
            stare_PIN2[0]=1;// {1,1,1,1};
            stare_PIN2[1]=1;
            stare_PIN2[2]=1;
            stare_PIN2[3]=1;
            stare_PIN3[0]=0;// {0,0,0,0};
            stare_PIN3[1]=0;
            stare_PIN3[2]=0;
            stare_PIN3[3]=0;
            stare_PIN4[0]=1;// {1,1,1,1};
            stare_PIN4[1]=1;
            stare_PIN4[2]=1;
            stare_PIN4[3]=1;
            //stare_PIN1_1 = 0;
            //stare_PIN2_1 = 0;
            //stare_PIN3_1 = 0;
            //stare_PIN4_1 = 0;
            //stare_PIN1_2 = 1;
            //stare_PIN2_2 = 1;
            //stare_PIN3_2 = 1;
            //stare_PIN4_2 = 1;
            //stare_PIN1_3 = 0;
            //stare_PIN2_3 = 0;
            //stare_PIN3_3 = 0;
            //stare_PIN4_3 = 0;
            //stare_PIN1_4 = 1;
            //stare_PIN2_4 = 1;
            //stare_PIN3_4 = 1;
            //stare_PIN4_4 = 1;
    break;

    case '5':
            stare_PIN1[0]=0;// {0,0,0,0};
            stare_PIN1[1]=0;
            stare_PIN1[2]=0;
            stare_PIN1[3]=0;
            stare_PIN2[0]=0;// {0,0,0,0};
            stare_PIN2[1]=0;
            stare_PIN2[2]=0;
            stare_PIN2[3]=0;
            stare_PIN3[0]=0;// {0,0,0,0};
            stare_PIN3[1]=0;
            stare_PIN3[2]=0;
            stare_PIN3[3]=0;
            stare_PIN4[0]=0;// {0,0,0,0};
            stare_PIN4[1]=0;
            stare_PIN4[2]=0;
            stare_PIN4[3]=0;
            //stare_PIN1_1 = 0;
            //stare_PIN2_1 = 0;
            //stare_PIN3_1 = 0;
            //stare_PIN4_1 = 0;
            //stare_PIN1_2 = 0;
            //stare_PIN2_2 = 0;
            //stare_PIN3_2 = 0;
            //stare_PIN4_2 = 0;
            //stare_PIN1_3 = 0;
            //stare_PIN2_3 = 0;
            //stare_PIN3_3 = 0;
            //stare_PIN4_3 = 0;
            //stare_PIN1_4 = 0;
            //stare_PIN2_4 = 0;
            //stare_PIN3_4 = 0;
            //stare_PIN4_4 = 0;
    break;
    
    default:
            stare_PIN1[0]=1;// {1,1,1,1};
            stare_PIN1[1]=1;
            stare_PIN1[2]=1;
            stare_PIN1[3]=1;
            stare_PIN2[0]=1;// {1,1,1,1};
            stare_PIN2[1]=1;
            stare_PIN2[2]=1;
            stare_PIN2[3]=1;
            stare_PIN3[0]=1;// {1,1,1,1};
            stare_PIN3[1]=1;
            stare_PIN3[2]=1;
            stare_PIN3[3]=1;
            stare_PIN4[0]=1;// {1,1,1,1};
            stare_PIN4[1]=1;
            stare_PIN4[2]=1;
            stare_PIN4[3]=1;
            //stare_PIN1_1 = 1;
            //stare_PIN2_1 = 1;
            //stare_PIN3_1 = 1;
            //stare_PIN4_1 = 1;
            //stare_PIN1_2 = 1;
            //stare_PIN2_2 = 1;
            //stare_PIN3_2 = 1;
            //stare_PIN4_2 = 1;
            //stare_PIN1_3 = 1;
            //stare_PIN2_3 = 1;
            //stare_PIN3_3 = 1;
            //stare_PIN4_3 = 1;
            //stare_PIN1_4 = 1;
            //stare_PIN2_4 = 1;
            //stare_PIN3_4 = 1;
            //stare_PIN4_4 = 1;
    break;
  }
 
  // // Serial.println(Timp_delay);
  
  
  //  }
  digitalWrite(Releu_PIN1, stare_PIN1[0]);
  digitalWrite(Releu_PIN2, stare_PIN1[1]);
  digitalWrite(Releu_PIN3, stare_PIN1[2]);
  digitalWrite(Releu_PIN4, stare_PIN1[3]);
   delay(Timp_delay);
  digitalWrite(Releu_PIN1, stare_PIN2[0]);
  digitalWrite(Releu_PIN2, stare_PIN2[1]);
  digitalWrite(Releu_PIN3, stare_PIN2[2]);
  digitalWrite(Releu_PIN4, stare_PIN2[3]);
   delay(Timp_delay);
  digitalWrite(Releu_PIN1, stare_PIN3[0]);
  digitalWrite(Releu_PIN2, stare_PIN3[1]);
  digitalWrite(Releu_PIN3, stare_PIN3[2]);
  digitalWrite(Releu_PIN4, stare_PIN3[3]);
   delay(Timp_delay);
  digitalWrite(Releu_PIN1, stare_PIN4[0]);
  digitalWrite(Releu_PIN2, stare_PIN4[1]);
  digitalWrite(Releu_PIN3, stare_PIN4[2]);
  digitalWrite(Releu_PIN4, stare_PIN4[3]);
   delay(Timp_delay);
  
  Serial.flush();
}
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module
NOCOMNCVCCGNDINLED1PWRRelay Module