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!