Hi Guys,
So I decided I was going to start learning how to use 7 Segment Displays and shift registers. I am using a 74HC595 to control the anodes of a 4 digit 7 segment display. And 2N3904s for the Cathodes. and a Dallas DS18B20 temperature sensor.
However, I am having extreme flicker/timing issues with the display. here is the code I am using. Instead of the display normally updating it cycles through each Digit with a about one second delay before displaying the next digit. So it displays one digit at a time. I have read that DallasTemp library causes delays. But the display shouldn't have large delays in between numbers? So I am slightly confused. Can anyone help me out?
Thanks,
Austin
/* * created by Rui Santos, http://randomnerdtutorials.com * Temperature Sensor Displayed on 4 Digit 7 segment common anode * 2013 * * Modified by Austin Pauley for use with DS18B20 * 2015 */ #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS A0 OneWire ds(ONE_WIRE_BUS); DallasTemperature sensors(&ds); DeviceAddress insideThermometer; const int digitPins[4] = { 5,4,3,2}; //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 { B11000000, //0 B11111001, //4 B10100100, //2 B10110000, //3 B10011001, //4 B10010010, //5 B10000010, //6 B11111000, //7 B10000000, //8 B10010000 //9 }; int digitBuffer[4] = { 0,0,0,0}; int digitScan = 0, flag = 0, soft_scaler = 0; ; float tempC, tempF; void setup(){ for (int i = 0; i<4; i++) { pinMode(digitPins[i], OUTPUT); } pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); sensors.begin(); sensors.getAddress(insideThermometer, 0); Serial.begin(9600); sensors.setResolution(9); } void updateDisp(){ for (byte j = 0; j < 4; j++) digitalWrite(digitPins[j], LOW); digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, B11111111); digitalWrite(latchPin, HIGH); delayMicroseconds(100); digitalWrite(digitPins[digitScan], HIGH); digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, digit[digitBuffer[digitScan]]); digitalWrite(latchPin, HIGH); digitScan++; if (digitScan>3) digitScan = 0; } float getTemp() { sensors.requestTemperatures(); tempF = sensors.getTempF(insideThermometer); } void loop(){ int temp = (int)getTemp(); digitBuffer[3] = int(temp) / 1000; digitBuffer[2] = (int(temp) % 1000) / 100; digitBuffer[1] = (int(temp) % 100) / 10; digitBuffer[0] = (int(temp) % 100) % 10; updateDisp(); }