Arduino Mega With 4 Nextion displays

Hello, I have a project with an Arduino Mega with 4 Nextion screens, 3 of 5 “and 1 of 7”. I have made the code to activate the lighting scenes, opening and closing curtains, and climate control from a screen. Is there a way to easily replicate this code using 4 serial ports of the arduino? Will it act and receive from all serial ports simultaneously? For example: - That it can activate a function from any of the screens and send the information to the rest of them.

Thanks!

}
  //serial 1


  if (Serial1.available() > 0) {

    setxxpoint = Serial1.read();
    Serial.println("****************************************1111111111111111111111port11111111111111111111");
    Serial.println("**********************************++++++++++++++*************************");
    Serial.print(setxxpoint);
    delay(150);



    //MOODS CONTROL



    if (setxxpoint == 55) //MOOD DAY
    {

      digitalWrite(Afoco3, 0);
      digitalWrite(Aled4, 0);
      digitalWrite(Aled5, 0);
      digitalWrite(Aled7, 0);
      digitalWrite(Aled8R, 1);
      digitalWrite(Aled8B, 1);
      digitalWrite(Aled9, 1);
      digitalWrite(Aled6, 1);
      digitalWrite(Aled10, 1); 
      // Serial1.println('7');
    }

    if (setxxpoint == 56) //MOOD LOVE
    {
      digitalWrite(Afoco3, 1);
      digitalWrite(Aled4, 1);
      digitalWrite(Aled5, 1);
      digitalWrite(Aled7, 0);  
      digitalWrite(Aled8R, 0);  
      digitalWrite(Aled8B, 1);  
      digitalWrite(Aled9, 0);
      digitalWrite(Aled6, 1);
      digitalWrite(Aled10, 0);  
      //  Serial1.println('8');

    }
    if (setxxpoint == 57) //MOOD NIGHT
    {
      digitalWrite(Afoco3, 1);
      digitalWrite(Aled4, 0);   
      digitalWrite(Aled5, 0);    
      digitalWrite(Aled7, 0);  
      digitalWrite(Aled8R, 1);  
      digitalWrite(Aled8B, 0);  
      digitalWrite(Aled9, 1);
      digitalWrite(Aled6, 1);
      digitalWrite(Aled10, 0);  
      // Serial1.println('9');

    }
    if (setxxpoint == 54) //MOOD MOVIE
    {
      digitalWrite(Afoco3, 1);
      digitalWrite(Aled4, 1);
      digitalWrite(Aled5, 0);  
      digitalWrite(Aled7, 1);
      digitalWrite(Aled8R, 1);
      digitalWrite(Aled8B, 1);
      digitalWrite(Aled9, 0);
      digitalWrite(Aled6, 0);    
      digitalWrite(Aled10, 1);
      // Serial1.println('6');

    }
    if (setxxpoint == 53) //MOOD SLEEP
    {
      digitalWrite(Afoco3, 1);
      digitalWrite(Aled4, 1);
      digitalWrite(Aled5, 1);  
      digitalWrite(Aled7, 1);
      digitalWrite(Aled8R, 1);
      digitalWrite(Aled8B, 1);
      digitalWrite(Aled9, 1);
      digitalWrite(Aled6, 1);   
      digitalWrite(Aled10, 1);
      //  Serial1.println('5');
    }
    
    //CURTAINS CONTROL
    if (setxxpoint == 65)
    {
      digitalWrite(led5, 1);
      digitalWrite(led4, 0);
      delay (200);
      digitalWrite(led5, 1);
      digitalWrite(led4, 1);
      //  Serial1.println('A');
    }

    if (setxxpoint == 66) //  OPEN
    {
      digitalWrite(led4, 1);
      digitalWrite(led5, 0);
      delay (200);
      digitalWrite(led5, 1);
      digitalWrite(led4, 1);
      // Serial1.println('B');
    }
    if (setxxpoint == 69) //  CLOSE
    {
      digitalWrite(led5, 0);
      digitalWrite(led4, 0);
      digitalWrite(led13, 0);
      digitalWrite(led14, 0);
      //  Serial1.println('E');
      delay (200);
      digitalWrite(led5, 1);
      digitalWrite(led4, 1);
      digitalWrite(led13, 1);
      digitalWrite(led14, 1);
      // Serial1.println('E');
      delay (200);
    }


    //SYNC UP MOTOR COURTAINS

    if (setxxpoint == 65) {
      Serial2.print("b4.val=");
      Serial2.print("1");
      Serial2.write(0xff);
      Serial2.write(0xff);
      Serial2.write(0xff);
      delay(500);
      Serial2.print("b4.val=");
      Serial2.print("0");
      Serial2.write(0xff);
      Serial2.write(0xff);
      Serial2.write(0xff);
      delay(500);

sketch_feb11b.ino (9.07 KB)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.