problem with 7 segment and ultrasonic distance sensor

The problem is the SevSeg::PrintOutput() code. He turns the segments on, waits awhile, then turns them off before returning. The wait seems to be to control brightness. Your delay is after all the digits are turned off.

I would use a different library, or change his library to remove the brightness feature so you can have whatever delays you want in your code.


void SevSeg::PrintOutput(){
int WaitTime = map(brightness,0,100,1,2000); //Calculate the delay once
for (byte seg=0;seg<8;seg++) {
//Turn the relevant segment on
digitalWrite(SegmentPins[seg],SegOn);

//For each digit, turn relevant digits on
for (byte digit=0;digit<NUM_DIGITS;digit++){
if (lights[digit][seg]==1) {
digitalWrite(DigitPins[digit],DigitOn);
}
//delay(200); //Uncomment this to see it in slow motion
}
delayMicroseconds(WaitTime);
//Turn all digits off
for (byte digit=0;digit<NUM_DIGITS;digit++){
digitalWrite(DigitPins[digit],DigitOff);
}

//Turn the relevant segment off
digitalWrite(SegmentPins[seg],SegOff);
}
}