const int digitPins[4] = { 4,5,6,7}; //4 common anode pins of the display const int clockPin = 11; //74HC595 Pin 11 const int latchPin = 12; //74HC595 Pin 12 const int dataPin = 13; //74HC595 Pin 14 const byte digit[10] = //seven segment digits in bits {// the following code is for common cathode but the following code inversed it so it becomes common anode. B00111111, //0 B00000110, //1 B01011011, //2 B01001111, //3 B01100110, //4 B01101101, //5 B01111101, //6 B00000111, //7 B01111111, //8 B01101111 //9 }; int digitBuffer[4] = { 0}; int digitScan = 0, flag=0, soft_scaler = 0; int tempPin = 0; void setup() { // Serial.begin(9600); for(int i=0;i<4;i++) { pinMode(digitPins[i],OUTPUT); // set up pinMode in a faster way } pinMode(tempPin, INPUT); pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void updateDisp(){ for(byte j=0; j<4; j++) digitalWrite(digitPins[j], LOW); // when there is only one line after the 'for' statement, it doesn't need a {} digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, B11111111); // clear all display first digitalWrite(latchPin, HIGH); delayMicroseconds(100); digitalWrite(digitPins[digitScan], HIGH); digitalWrite(latchPin, LOW); if(digitScan==2) // the inverse '~' is to fit it for the common anode application. shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] | B10000000)); //print the decimal point on the 3rd digit else shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]); digitalWrite(latchPin, HIGH); digitScan++; if(digitScan>3) digitScan=0; } void loop() { int tempReading = analogRead(tempPin); double tempK = log(10000.0 * ((1024.0 / tempReading - 1))); tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin float tempC = tempK - 273.15; // Convert Kelvin to Celcius digitBuffer[3] = int(tempC)/1000; digitBuffer[2] = (int(tempC)%1000)/100; digitBuffer[1] = (int(tempC)%100)/10; digitBuffer[0] = (int(tempC)%100)%10; updateDisp(); delay(2); // Serial.println(tempC); }