Turning Serial data read from input (Ultrasonic) and outputting to 4-digit disp.

I’m having issues with turning the information on my buffer from the Ultrasonic sensor and putting it on my 4-digit display. Morse-so the issue seems to be in the way that the data is structured. I setup an array[4] and I’m trying to separate the data so that if I get two values of 45 and 50, the led doesn’t show 4550. I know there is a way to separate these two inputs, just don’t know how. Any help would be appreciated. I attached the code. The display i’m using is a TM1637 display and the sensor is the hc-sr04.
Any other questions feel free to ask.

Quad_display.ino (1.22 KB)

Welcome to the Forum. Please read these two posts:

General Guidance and How to use the Forum
and
Read this before posting a programming question ...
You may also find useful information that would answer your question here:
Useful links - check here for reference posts / tutorials

It is important to provide as much of the information that is needed to solve your problem as you can, in your first posts. The forum link above has guidelines for posting in a standard way that makes it easiest for people to provide you with useful answers. Making an effort to do this will greatly increase the number and quality of helpful responses that you get.

In this case, the problem is that you have added your sketch as an attachment. Unless the sketch is too large, it's better if you post your code (using code tags!), rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.
Please edit your post and insert your code inside it, using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.

#include <TM1637.h>
#define Echo_pin 5
#define Trig_pin 4

#define CLK 7//pins definitions for TM1637 and can be changed to other ports
#define DIO 6
TM1637 tm1637(CLK,DIO);

int distance[4];

void setup() {
  // put your setup code here, to run once:

pinMode ( Echo_pin, INPUT);             
pinMode ( Trig_pin, OUTPUT);
Serial.begin (9600);
tm1637.init();
tm1637.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
   Serial.println("<Arduino is ready>");
int data;

}


void loop() 
{
    for (int i=0; i<4; i++)                           // This is where the issue is. Need to add some code
                                                              // The current for loop just prints out the numbers 
                                                              //   nonstop, I need a way to separate each value
                                                              //  measured by the Ultrasonic sensor, i.e 40,100,34,1.
    {                                                        //  Right now it would print it as 4010, 0341.
     distance[i]= measure();
    
    Serial.println(distance[i]);
    }
  
             

  int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9};//0~9,A,b,C,d,E,F
  int8_t ListDisp[4];
  unsigned char i = 0;
  unsigned char count = 0;
  
  tm1637.display(0,distance[3]);                  / /digit 1 input parameter(digit#,value to be display)
    tm1637.display(1,distance[2]);                // digit 2 input
    tm1637.display(2,distance[1]);                // digit 3
    tm1637.display(3,distance[0]);                // digit 4
    delay(300);



}



int measure()
{
  digitalWrite(Trig_pin, HIGH);
  digitalWrite(Trig_pin, LOW);
  int distance = pulseIn(Echo_pin, HIGH, 15000) / 50;
  delay(3000);
  return constrain(distance, 1, 300);
}

OK there is the code. I’m reading the articles you posted too. Any help would still be appreciated. I’m also watching videos on youtube. Hopefully someone figures it out faster than I do :).