Make two serial.read run together

hello, i have a project that will display to 3 digit 7 segment and blink led from serial input. the problem is the display will show after the blink led finish. that even worst when i input more than 10 blinks. what i want is the display will come together with the blink that i cant figure it out. but my friend once said to used interrupt and still doesnt find it.

char number;                  
int flag=0;
int cSer=0;
int iX=0;
int iY=0;                     // Jumlah digit yang akan ditampilkan
int iEks=0;
int i;
int x;
String data="";
//void segmen ();
//void bling();

/****Array*****/
int tmpArr[4]={255,255,255,255};  // incoming serial data
int dsegArr[4]={255,255,255,255}; // the data will showing to 7 segmen
void loop(){
 if(Serial.available() > 0)      {
           number=Serial.read();
          int inChar = number;     
          if(isDigit(inChar))data += (char)inChar;
          if(inChar=='\n'|| inChar=='\r'){
            x=data.toInt();
            Serial.print("value");
            Serial.println(x);
            Serial.println(x);
            for(i=0; i<x; i++){
                digitalWrite(ledPin, state);
              digitalWrite(7, HIGH);
              delay(100);
              digitalWrite(7, LOW);
              delay(100);
             
            }
            data="";
          }
        tmpArr[iX++] = number-48;                                    
        if (number==13 || number==10)                       
          {                        
          for(iY=0; iY<iX; iY++){dsegArr[iY]=tmpArr[iY];}
          if(iY==4)
          {
          
            Serial.print("Ratusan segment display:");
            Serial.println(dsegArr[0]);  
            Serial.print("Puluhan segment display:");
            Serial.println(dsegArr[1]);
            Serial.print("Satuan segment display:");
            Serial.println(dsegArr[2]);                                  
          }
          if(iY==3)
          {
            Serial.print("Ratusan segment display:");
            Serial.println('0');
            Serial.print("Puluhan segment display:");
            Serial.println(dsegArr[0]);
            Serial.print("Satuan segment display:");
            Serial.println(dsegArr[1]);                                  
          }
          if(iY==2)
          {  
            Serial.print("Ratusan segment display:");
            Serial.println('0');
            Serial.print("Puluhan segment display:");
            Serial.println('0');  
            Serial.print("Satuan segment display:");
            Serial.println(dsegArr[0]);
            /*iEks = dsegArr[0];
            for (int ex = 0; ex < iEks; ex++){
              digitalWrite(led, LOW);
              delay(500);
              digitalWrite(led, HIGH);
            }*/                            
          }
          iX=0;
        }
      } 

Please post all your code... not just pieces of it.

Using delay() is never a good idea if you want multiple things to happen at the same time.

Can you explain in more detail exactly what your sketch is supposed to do? Use Google Translate if English is not your first language.

Dude... don't post the same thing twice.

https://forum.arduino.cc/t/make-two-serial-data-run-together/1011320

@rogh

Your other topic on the same subject deleted.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

so sorry its the first time, i cant delete the first one.

I have already deleted it

//#include <SevenSeg.h>
#include "SevenSeg.h"
const byte ledPin = 13;

#define led 7
#define seg3 40
#define seg2 41
#define seg1 42
const int Gnd = 6;
const int trig_led = 2;
volatile byte state = false;

//Defines the segments A-G: SevenSeg(A, B, C, D, E, F, G);
SevenSeg disp (30,31,32,33,34,35,36);
//Number of 7 segments
const int numOfDigits =3;
//CC(or CA) pins of segment
int digitPins [numOfDigits]={40,41,42};
/****Variables*****/
char number;                  
int flag=0;
int cSer=0;
int iX=0;
int iY=0;                     // Jumlah digit yang akan ditampilkan
int iEks=0;
int i;
int x;
String data="";
//void segmen ();
//void bling();

/****Array*****/
int tmpArr[4]={255,255,255,255};  // yg data dari serial tampung sini
int dsegArr[4]={255,255,255,255}; // data yang ditampilkan di 7 segmen tampung disini

void setup() 
  {	
  Serial.begin(9600);
  //Defines the number of digits to be "numOfDigits" and the digit pins to be the elements of the array "digitPins"
  disp.setDigitPins ( numOfDigits , digitPins );
  //Only for common cathode 7segments
  disp.setCommonAnode();
  //Control brightness (values 0-100);
  disp.setDutyCycle(50);
  pinMode(Gnd, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(2, INPUT);
  pinMode(seg1,OUTPUT);
  pinMode(seg2,OUTPUT);
  pinMode(seg3,OUTPUT);
  pinMode(led,OUTPUT);
 // attachInterrupt(digitalPinToInterrupt(2), segmen, CHANGE);

 }



        /*number=Serial.read();

          */
              
    /*
    ---- ALUR PROCEDURE MENERIMA DATA SERIAL ----
    1. Tampung Data Serial ke Var Number
    2. Kurangi isi data number dengan  0x30 , hasilnya adalah index ke table segment
    3. Pindahakan data ke array table tmpArr[]
    4. Cek data serial apakah data terakhir 0x0A atau 0x0D 
       Y : Update data segmen , copy tmpArr[] -> dsegArr[]
           Debug Diserial Monitor , memastikan data benar
           Variable Counter iX di Nolkan
           Catat nilai variable iY                                                                       
       N : Keluar Prosedure , Next Prosedure
    */
     
    
  


void loop(){
 if(Serial.available() > 0)
      {
 
          number=Serial.read();
          int inChar = number;     
          if(isDigit(inChar))data += (char)inChar;
          if(inChar=='\n'|| inChar=='\r'){
            x=data.toInt();
            Serial.print("value");
            Serial.println(x);
            Serial.println(x);
            for(i=0; i<x; i++){
                digitalWrite(ledPin, state);
              digitalWrite(7, HIGH);
              delay(100);
              digitalWrite(7, LOW);
              delay(100);
             
            }
            data="";
          }
    
    /*
    ---- ALUR PROCEDURE MENERIMA DATA SERIAL ----
    1. Tampung Data Serial ke Var Number
    2. Kurangi isi data number dengan  0x30 , hasilnya adalah index ke table segment
    3. Pindahakan data ke array table tmpArr[]
    4. Cek data serial apakah data terakhir 0x0A atau 0x0D 
       Y : Update data segmen , copy tmpArr[] -> dsegArr[]
           Debug Diserial Monitor , memastikan data benar
           Variable Counter iX di Nolkan
           Catat nilai variable iY                                                                       
       N : Keluar Prosedure , Next Prosedure
    */
 
                           
        tmpArr[iX++] = number-48;                                    
        if (number==13 || number==10)                       
          {                        
          for(iY=0; iY<iX; iY++){dsegArr[iY]=tmpArr[iY];}
          if(iY==4)
          {
          
            Serial.print("Ratusan segment display:");
            Serial.println(dsegArr[0]);  
            Serial.print("Puluhan segment display:");
            Serial.println(dsegArr[1]);
            Serial.print("Satuan segment display:");
            Serial.println(dsegArr[2]);                                  
          }
          if(iY==3)
          {
            Serial.print("Ratusan segment display:");
            Serial.println('0');
            Serial.print("Puluhan segment display:");
            Serial.println(dsegArr[0]);
            Serial.print("Satuan segment display:");
            Serial.println(dsegArr[1]);                                  
          }
          if(iY==2)
          {  
            Serial.print("Ratusan segment display:");
            Serial.println('0');
            Serial.print("Puluhan segment display:");
            Serial.println('0');  
            Serial.print("Satuan segment display:");
            Serial.println(dsegArr[0]);
            /*iEks = dsegArr[0];
            for (int ex = 0; ex < iEks; ex++){
              digitalWrite(led, LOW);
              delay(500);
              digitalWrite(led, HIGH);
            }*/                            
          }
          iX=0;
        }
      } 
      
       
/*
    ---- ALUR PROCEDURE MENERIMA DATA SERIAL ----
    1. Cek Nilai Variable iY
    2. iY==4 -> 3 digit segmen ON, PROCEDURE satuan dan puluhan dan ratusan
    2. iY==3 -> 2 digit segmen ON, PROCEDURE satuan dan puluhan
    2. iY==2 -> 1 digit segmen ON, PROCEDURE hanya satuan
    3. Atur Delay scanning ON/OFF 7 segmen
    4. Keluar PROCEDURE kembali ke program utama
*/
    if(iY==4)
    {      
      disp.writeDigit(dsegArr[0]);          
      digitalWrite(seg3, LOW);
      digitalWrite(seg2, HIGH); 
      digitalWrite(seg1, HIGH);

      delayMicroseconds(100);
      
      digitalWrite(seg3, HIGH);
      digitalWrite(seg2, HIGH);
      digitalWrite(seg1, HIGH);

      /*iEks = dsegArr[0] * 100;
      for (int q = 0; q < iEks; q++){
        digitalWrite(led, LOW);
        delay(500);
        digitalWrite(led, HIGH);
      }*/
      
      disp.writeDigit(dsegArr[1]);
      digitalWrite(seg3, HIGH);   
      digitalWrite(seg2, LOW);
      digitalWrite(seg1, HIGH);

      delayMicroseconds(100);

      digitalWrite(seg3, HIGH);
      digitalWrite(seg2, HIGH);
      digitalWrite(seg1, HIGH);
      delayMicroseconds(100);

      /*iEks = dsegArr[1] * 10;
      for (int q = 0; q < iEks; q++){
        digitalWrite(led, LOW);
        delay(500);
        digitalWrite(led, HIGH);
      }*/

      disp.writeDigit(dsegArr[2]);
      digitalWrite(seg3, HIGH);   
      digitalWrite(seg2, HIGH);
      digitalWrite(seg1, LOW);

      delayMicroseconds(100);

      digitalWrite(seg3, HIGH);
      digitalWrite(seg2, HIGH);
      digitalWrite(seg1, HIGH);
      delayMicroseconds(100);

      /*iEks = dsegArr[2];
      for (int q = 0; q < iEks; q++){
        digitalWrite(led, LOW);
        delay(500);
        digitalWrite(led, HIGH);
      }*/
    }

    if(iY==3)
    {      
      disp.writeDigit(dsegArr[0]);          
      digitalWrite(seg2, LOW);
      digitalWrite(seg1, HIGH);

      delayMicroseconds(100);
      
      digitalWrite(seg3, HIGH);
      digitalWrite(seg2, HIGH);
      digitalWrite(seg1, HIGH);

      /*iEks = dsegArr[0] * 10;
      for (int q = 0; q < iEks; q++){
        digitalWrite(led, LOW);
        delay(500);
        digitalWrite(led, HIGH);
      }*/
      
      disp.writeDigit(dsegArr[1]);    
      digitalWrite(seg2, HIGH);
      digitalWrite(seg1, LOW);

      delayMicroseconds(100);

      digitalWrite(seg3, HIGH);
      digitalWrite(seg2, HIGH);
      digitalWrite(seg1, HIGH);
      delayMicroseconds(100);

      /*iEks = dsegArr[1];
      for (int q = 0; q < iEks; q++){
        digitalWrite(led, LOW);
        delay(500);
        digitalWrite(led, HIGH);
      }*/
    }

    if(iY==2)
    {      
      disp.writeDigit(dsegArr[0]);    
      digitalWrite(seg1, LOW);
      
      delayMicroseconds(100);
      
      digitalWrite(seg3, HIGH);
      digitalWrite(seg2, HIGH);
      digitalWrite(seg1, HIGH);
      //delayMicroseconds(100);

      /*iEks = tmpArr[0];
      for (int q = 0; q < iEks; q++){
        digitalWrite(led, LOW);
        delay(500);
        digitalWrite(led, HIGH);
        delay(500);
      }*/
    }
    }
  

The point is, I want to display some data (number) to turn on the LED according to the input, and the inputted data will appear on the 7 segment display. The current problem is that the display must wait for the LED to finish blinking and then the data appears on the display.

How about you setup a timer responsible for the LED frequency and set it up as an external trigger for the GPIO port responsible for the LED on your board. Then when you receive data you start the timer (put an interrupt on the timer so that when it reaches a certain amount of trigger generated it stops) the LED blinks in the background and you can take care of your display ?
(Only an idea)

What input are you expecting from the Serial Monitor?

One character (digit) at a time?

Multiple digits?

If a new digit arrives should the blinking stop for the previous digit if hasn't completed?

I tried with the millis(), but haven't found it yet. Finally, the LED is not blinking but the display appears. ha ha ha

input must be 1 - 3 digits. depends on input from keyboard but only numbers. if a new digit appears, it must wait until the previous digit has been completed first

So a number from 0 to 999 ?

And you display the number on your 3 x 7 segment display?

And you also flash an LED the number of times of the number you receive? So if you receive 550, you flash the LED 550 times? ... so 200ms x 550 = almost 2 minutes ? Is that correct?

yeah,, right..

So your problem is that the number doesn't display on the 7 segment display until after the LED has finished flashing?

Why don't you just display the number on the 7 segment display first, and then flash the LED?

I have not looked closely at the sketch but I suspect that the display needs to be continually updated which will not happen whilst the LED blinking is happening as it is currently implemented

I've tried before. but the program still executes the LED flash command first.

the code above has gone according to plan, it's just that the display is delayed because it has to finish the flash led first. and it will get worse if we input a large number.

I think this problem can be solved maybe by using interrupt, millis(), or do-while. but unfortunately i am very newbie to all three

You can solve it with millis()

See Using millis() for timing. A beginners guide, Several things at the same time and the BlinkWithoutDelay example in the IDE