7seg and ultrasonic

I USE THIS ULTRASONIC AS COUNT

I WANT TO SEE THE NUMBER ON THE 7 SEGMENT

SOMEONE CAN HELP ME TO Combine the codes.

7SEG CODE:

int D1=9;

int D2=10;

int D3=11;

int D4=12;

int a=2;

int b=3;

int c=4;

int d=5;

int e=6;

int f=7;

int g=8;

void setup(){

pinMode(D1,OUTPUT);

pinMode(D2,OUTPUT);

pinMode(D3,OUTPUT);

pinMode(D4,OUTPUT);

pinMode(a,OUTPUT);

pinMode(b,OUTPUT);

pinMode(c,OUTPUT);

pinMode(d,OUTPUT);

pinMode(e,OUTPUT);

pinMode(f,OUTPUT);

pinMode(g,OUTPUT);

}

void loop(){

digitalWrite(9,HIGH);

digitalWrite(10,HIGH);

digitalWrite(11,HIGH);

digitalWrite(12,HIGH);

zero();

delay(1000);

one();

delay(1000);

two();

delay(1000);

three();

delay(1000);

four();

delay(1000);

five();

delay(1000);

six();

delay(1000);

seven();

delay(1000);

eight();

delay(1000);

nine();

delay(1000);

}

void zero(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,HIGH);

}

void one(){

digitalWrite(a,HIGH);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

}

void two(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,HIGH);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,HIGH);

digitalWrite(g,LOW);

}

void three(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,LOW);

}

void four(){

digitalWrite(a,HIGH);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

}

void five(){

digitalWrite(a,LOW);

digitalWrite(b,HIGH);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

}

void six(){

digitalWrite(a,LOW);

digitalWrite(b,HIGH);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

}

void seven(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,HIGH);

digitalWrite(e,HIGH);

digitalWrite(f,HIGH);

digitalWrite(g,HIGH);

}

void eight(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,LOW);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

}

void nine(){

digitalWrite(a,LOW);

digitalWrite(b,LOW);

digitalWrite(c,LOW);

digitalWrite(d,LOW);

digitalWrite(e,HIGH);

digitalWrite(f,LOW);

digitalWrite(g,LOW);

}

I HAVE THIS CODE FOR 7 SEGMENT

AND THIS FOR ULTRASONIC:

#define trigPin A1

#define echoPin A0

int state = 0;

int count = 0;

int set_distance = 10;

void setup()

{

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

}

void loop()

{

long duration, distance;

digitalWrite(trigPin, LOW); /// trig חיבור ה

delayMicroseconds(2);

digitalWrite(trigPin, HIGH); /// שליחת פולס

delayMicroseconds(10);

digitalWrite(trigPin, LOW); /// סיום שליחת הפולס

duration = pulseIn(echoPin, HIGH); /// מדידת זמן

distance = (duration / 58); /// נוסחה לחישוב המרחק

if (state == 0 && (distance < set_distance) ) {

state = 1;

count++;

Serial.println(count);

}

if (distance > set_distance) {

state = 0;

}

delay(100);

}

Wow. Rarely have I seen a question so badly posted

It is not an introductory tutorial so it has been moved, the question was written in capitals, the code was not formatted and it was not posted on code tags

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

...or so frequently :frowning:

I don't see where the 7-Segment sketch is selecting which of the four digits to display. It looks like it is either selecting NO digits or ALL digits. Neither is good for displaying a number (except 0000, 1111, 2222, 3333...). You need to get your 7-Segment sketch working so it can display four different digits.