Delaying Between Shift Out Codes

Hi,

Basically Im trying to get a 4 digit 7 segment display to work through a shift register. I don't need to display numbers, just do a few animations. So how I've animated it without the shift register, is to send current, which lights up rows, but I've then changed the pinMode mid sketch of any digits I don't want on at all.

But when I get to powering it through the shift register, I can't use the delay function or change the pin mode's between sending data.

This is my current working (displays top squares of first 2 digits) code:

int dataPin = 5; //Define which pins will be used for the Shift Register control
int latchPin = 6;
int clockPin = 7;

int s1 = 8;

int s2 = 9;
int s3 = 10;
int s4 = 11;

void setup()
{
pinMode(dataPin, OUTPUT); //Configure each IO Pin
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);

pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, INPUT);
pinMode(s4, INPUT);

}

void loop()
{
{

digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, 15); //Send the data

digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data

}
}

But then when I add this, the squares flash on and off very quickly and dimly with an off interval of about a second.

delay(1000);

digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, 0); //Send the data

digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data

Does anybody know how to sort this out? And will utilising the changing of pin modes end up making things more complicated down the line?

Thank you,
Kadoodle

You turn off the LEDs and straight away you turn them on again, then you wait a second before turning them off again.
The simple way is to add another delay after you turn them off.

Changing the pin mode does absoloutly nothing for you.

Just tried it. But still the flashing lights everytime there's a delay() added.

I've been changing the pinMode to disable certain digits from showing up at all.

FYI: Please bear with me as I am a beginner, so even any clues would be appreciated to help me to find the solution

Yes you are programming the the display to do exactly that.
What do you want it to do?

Changing the pinMode is wrong. It will not do what you want, do not do it.

Code tags, not quote tags.

A schematic diagram of some kind would help to let us know what's wired to what.

And you said "just tried it". What is "it"? When you try something, post the sketch that you tried.

This is what I’ve got right now (picture)

I want to delay on these 2 lit squares for 1 second. Then turn the second one off, by changing the pinmode of s2 to input. This is how I only have 2 squares and not 4 showing, because s3 and s4 have been set to inputs.

Give me a second to upload the code and pins

Sorry, don’t know how to show it in code.

Pins s1-s4 are connected to pins 6, 8, 9 and 12 of the display.

The rest of the displays pins (sending to a-g) are connected to Q0-Q6

int dataPin = 5; //Define which pins will be used for the Shift Register control
int latchPin = 6;
int clockPin = 7;

int s1 = 8;

int s2 = 9;
int s3 = 10;
int s4 = 11;

void setup()
{
pinMode(dataPin, OUTPUT); //Configure each IO Pin
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);

pinMode(s1, OUTPUT);
pinMode(s2, OUTPUT);
pinMode(s3, INPUT);
pinMode(s4, INPUT);

}

void loop()
{
{

digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, 15); //Send the data

digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data

digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, 0); //Send the data

digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data

}

}

Pins s1-s4 are connected to pins 6, 8, 9 and 12 of the display.

The rest of the displays pins (sending to a-g) are connected to Q0-Q6

int dataPin = 5;        //Define which pins will be used for the Shift Register control
int latchPin = 6;
int clockPin = 7;


int s1 = 8;

int s2 = 9;
int s3 = 10;
int s4 = 11;

void setup()
{
    pinMode(dataPin, OUTPUT);       //Configure each IO Pin
    pinMode(latchPin, OUTPUT);
    pinMode(clockPin, OUTPUT);

  pinMode(s1, OUTPUT);
    pinMode(s2, OUTPUT);
  pinMode(s3, INPUT);
  pinMode(s4, INPUT);


}

void loop()
{
    {
      

digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, 15);          //Send the data

digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data


digitalWrite(latchPin, LOW);             //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, 0);          //Send the data

digitalWrite(latchPin, HIGH);            //Pull latch HIGH to stop sending data

  }

you will need to put some time in between switching them or you may not even notice what happened.

also recommend that you pass binary numbers when you shift out and visually map each of the seven segments to the binary number:

so all off

B00000000

or all on

B01111111

or your lower four box:

B00001111 = decimal 15

much easier to visualize, I think

int dataPin = 5;        //Define which pins will be used for the Shift Register control
int latchPin = 6;
int clockPin = 7;
int s1 = 8;
int s2 = 9;
int s3 = 10;
int s4 = 11;

byte ledOff = B00000000; // Decimal zero, of course
byte ledOn  = B00001111;  //Decimal 15

//
void setup()
{
  pinMode(dataPin, OUTPUT);       //Configure each IO Pin
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, INPUT);
  pinMode(s4, INPUT);
}

void loop()
{
  digitalWrite(latchPin, LOW);
  shiftOut(dataPin, clockPin, MSBFIRST, ledOn); 
  digitalWrite(latchPin, HIGH); 
  delay(1000); // if you don't have a period of time in between switching, you may not notice that it was lit!
  digitalWrite(latchPin, LOW); 
  shiftOut(dataPin, clockPin, MSBFIRST, ledOff);
  digitalWrite(latchPin, HIGH); 
  delay(1000);
}

Pins s1-s4 are connected to pins 6, 8, 9 and 12 of the display.

So why do you not do anything with them in the code?

All your code does is to write alternately all the shift register bits on then all of them off.

READ the how to use the forum sticky.

I asked for a schematic not a photograph. And do not post photographs that are so ridiculously large.

There is no way you can get the display you show on the photograph from the code you posted if it is wired up as you describe. So get serious about telling us about what you have.