4-7sigment with shift register 74hc595

Hey,

I'm trying to do counter on the 7 segment display. My problem is that the first number also shown (even bolder) on the second digit as well.
I connected the Arduino to the shift register (3 pins) and 4 pins of the Arduino for every digit (anode) and connected the shift register to the 7sigment cathodes (a-g);

The number on the photo is under 10 and should be just on the right digit.

My code is:

 byte datanum[] = { B10000001, B11001111, B10010010, B10000110, B11001100, B10100100, B10100000, B10001111, B10000000, B10001100, B01111111};


int dataPin = 2;        //Define which pins will be used for the Shift Register control
int latchPin = 3;
int clockPin = 4;
int shaot1Pin = 8;
int shaot0Pin = 7;
int dakot1Pin = 6;
int dakot0Pin = 5;
int time = 300;
long previousMillis = 0;
long interval = 1000;
int i = 0;
//int dd = 1000;


void setup()
{
	Serial.begin(9600);
	pinMode(dataPin, OUTPUT);       //Configure each IO Pin
	pinMode(latchPin, OUTPUT);
	pinMode(clockPin, OUTPUT);
	pinMode(dakot0Pin, OUTPUT);
	pinMode(dakot1Pin, OUTPUT);
	pinMode(shaot0Pin, OUTPUT);
	pinMode(shaot1Pin, OUTPUT);

}

void loop()
{

	unsigned long currentMillis = millis();
	if (currentMillis - previousMillis > interval) {
		// save the last time 
		previousMillis = currentMillis;
		displaynumber1(i);
		Serial.println(i);
		i++;
	}
	else displaynumber1(i);
		

	
}
		



void displaynumber1(int fullnum){
	int dakot0;
	int dakot1;
	int shaot0;
	int shaot1;

	if (fullnum < 10){
		dakot0 = fullnum % 10;
		dakot1 = 10;
		shaot0 = 10;
		shaot1 = 10;
	}

	else if (fullnum > 9 && fullnum < 100){
		dakot0 = fullnum % 10;
		dakot1 = (fullnum / 10) % 10;
		shaot0 = 10;
		shaot1 = 10;
	}

	else if (fullnum > 99 && fullnum < 1000){
		dakot0 = fullnum % 10;
		dakot1 = (fullnum / 10) % 10;
		shaot0 = (fullnum / 100) % 10;
		shaot1 = 10;
	}
	else if (fullnum > 999){
		dakot0 = fullnum % 10;
		dakot1 = (fullnum / 10) % 10;
		shaot0 = (fullnum / 100) % 10;
		shaot1 = fullnum / 1000;
	}

	

	//dakot 0
	
	digitalWrite(dakot0Pin, HIGH);
	digitalWrite(latchPin, LOW);          //Pull latch LOW to start sending data
	shiftOut(dataPin, clockPin, LSBFIRST, datanum[dakot0]);         //Send the data
	delayMicroseconds(time);
	digitalWrite(latchPin, HIGH);         //Pull latch HIGH to stop sending data
	digitalWrite(dakot0Pin, LOW);
	//delayMicroseconds(dd);

	//dakot 1
	digitalWrite(dakot1Pin, HIGH);
	digitalWrite(latchPin, LOW);          //Pull latch LOW to start sending data
	shiftOut(dataPin, clockPin, LSBFIRST, datanum[dakot1]);         //Send the data
	//delayMicroseconds(time);
	digitalWrite(latchPin, HIGH);         //Pull latch HIGH to stop sending data
	digitalWrite(dakot1Pin, LOW);
	//delayMicroseconds(dd);

	////shaot 0
	//digitalWrite(shaot0Pin, HIGH);
	//digitalWrite(latchPin, LOW);          //Pull latch LOW to start sending data
	//shiftOut(dataPin, clockPin, LSBFIRST, datanum[shaot0]);         //Send the data
	//delayMicroseconds(time);
	//digitalWrite(latchPin, HIGH);         //Pull latch HIGH to stop sending data
	//digitalWrite(shaot0Pin, LOW);
	////delayMicroseconds(dd);

	////shaot 1
	//digitalWrite(shaot1Pin, HIGH);
	//digitalWrite(latchPin, LOW);          //Pull latch LOW to start sending data
	//shiftOut(dataPin, clockPin, LSBFIRST, datanum[shaot1]);         //Send the data
	//delayMicroseconds(time);
	//digitalWrite(latchPin, HIGH);         //Pull latch HIGH to stop sending data
	//digitalWrite(shaot1Pin, LOW);
	////delayMicroseconds(dd);


}

I tried to play with the delays and with the code, but I have not solution.
Anybody?

Thanks.

It's a little hard to see just how you are doing the displaying, but I think you are using 1 shift register and multiplexing that across multiple displays.

If that is the case, then you are most likely suffering from "ghosting".

There is a specific way of doing multiplexed displays, and people often overlook or forget it. The correct sequence should be:

  1. Disable all commons
  2. Load shift register
  3. Enable one common
  4. Delay
  5. Disable all commons
  6. Load shift register
  7. Enable next common
  8. Delay
    ... etc ...

It's important to ensure all commons are disabled while you are updating the shift register, as the data from the previous digit will still be there until the current digit has been shifted in and latched. You could theoretically have the shifting as part of the delay, however the latching MUST be done with all the commons disabled.

Thanks!

I change the that:

digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
digitalWrite(dakot0Pin, HIGH);
shiftOut(dataPin, clockPin, LSBFIRST, datanum[dakot0]); //Send the data
delayMicroseconds(time);
digitalWrite(dakot0Pin, LOW);
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data

and its working!
:smiley: