DS18B20 Digital Thermometer with 4 Digit 7 Segment Display

Hello,

For my first Arduino project I'm trying to use a 4 digit 7 segment display to display the temperature captured by DS18B20. I'm using two shift registers to control the display, as per http://tronixstuff.wordpress.com/2010/05/14/getting-started-with-arduino-chapter-six/. My problem is that when I run the code (partially shown):

void cleardisplay() //turn off all segments of all digits
{
for (int a=0;a<4;a++)
{
digitalWrite(latchpin,LOW);
shiftOut(datapin,clockpin,MSBFIRST,posdisp[a]); //select position to clear
shiftOut(datapin,clockpin,MSBFIRST,0); //clear selected position
digitalWrite(latchpin,HIGH);
}
}

void digdisp(int digit, int location)
{
digitalWrite(latchpin,LOW);
shiftOut(datapin,clockpin,MSBFIRST,posdisp[location]); //put input number in correct location
shiftOut(datapin,clockpin,MSBFIRST,segdisp[digit]); //display input number
digitalWrite(latchpin,HIGH);
}

void getTemperature()
{
sensors.requestTemperatures(); // Send the command to get temperatures
temperatureValue = sensors.getTempCByIndex(0);
Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"?
}

void TDisplay(int value)
{
thousands=value/1000;
hundreds=(value%1000)/100;
tens=(value%100)/10;
ones=value%10;

digdisp(thousands,0);
digdisp(hundreds,1);
digdisp(tens,2);
digdisp(ones,3);
cleardisplay();
}

void loop()
{
getTemperature();
TDisplay(temperatureValue);
}

The display flickers, because getTemperature() in the loop is turning off the display every time it retrieves new temperature data. Ideally I want to keep the TDisplay digits showing on the foreground while I get new temperature data, and then replace the old digits on the display with new ones, but I'm not sure how I would go about doing that. Any advice is appreciated!

You're reading the temperature every time you have displayed your characters so your sketch is spending most of it's time reading the temperature and not so much time displaying the characters.
It's probably enough to read the temperature once a second (or once every 30 seconds).
Use the millis counter to determine how long it is since you last did a getTemperature() and do it only when a certain amount of time has passed.
See the Blink Without Delay example: http://arduino.cc/en/Tutorial/BlinkWithoutDelay

You could also use some other external chip like a MAX7219 to handle the 4 segment display and not have to worry a bit about flicker while you process other things but it should also be possible to reduce the flickering with your current setup by not reading the temperature in every loop.

Thanks for the help. I tried putting millis() into the code, and while it did improve the flickering, I was still not satisfied. So I bought some MAX7219 and will just let it drive the display while Arduino takes care of the temperature.