## Logic Behind Displaying 7 in the 7th SSD out of 8 Seven Segment Displays (Part 9 of 16)

by realfinetime  |  in Seven Segment Display at  23:00

We have found the circuit for controlling a cluster of 8 common cathode seven segment displays using arduino and 74595 in previous blogs. Click here to start reading from the beginning of "controlling a cluster of eight common cathode seven segment displays using arduino and 74595".

Here, we will generate an arduino program that will display "7." in seventh common cathode seven segment display as given below.

Circuit is given here. Complete that circuit and upload the following program to your arduino board.

int latchPin = 12;  //Pin connected to ST_CP of 1st 74595
int clockPin = 13;  //Pin connected to SH_CP of 1st 74595
int dataPin = 11;   //Pin connected to DS of 1st 74595

int latchPin2 = 6;  //Pin connected to ST_CP of 2nd 74595
int clockPin2 = 7;  //Pin connected to SH_CP of 2nd 74595
int dataPin2 = 5;  //Pin connected to DS of 2nd 74595

void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);

pinMode(latchPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);
pinMode(dataPin2, OUTPUT);
}

void loop() {

// take the latchPin low so the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
//Send 1 0 0 0 0 1 1 1 (135) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 1st 74595
shiftOut(dataPin, clockPin, MSBFIRST, 135);
// shift out the bits:
digitalWrite(latchPin, HIGH);

// take the latchPin low so the LEDs don't change while you're sending in bits:
digitalWrite(latchPin2, LOW);
//Send 1 0 1 1 1 1 1 1 (191) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
shiftOut(dataPin2, clockPin2, MSBFIRST, 191);
// shift out the bits:
digitalWrite(latchPin2, HIGH);

/********* Turn off all the LEDs *********/

// take the latchPin low so the LEDs don't change while you're sending in bits:
digitalWrite(latchPin2, LOW);
//Send 1 1 1 1 1 1 1 1 (255) to Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of 2nd 74595
shiftOut(dataPin2, clockPin2, MSBFIRST, 255);
// shift out the bits:
digitalWrite(latchPin2, HIGH);
}

"7." will be displayed in the seventh common cathode seven segment display. All other seven segment displays will turn off.
Working of program

Working of program is simple. Program will send 135 (1 0 0 0 0 1 1 1) to the first 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of first 74595 becomes 1 0 0 0 0 1 1 1. After that, program will send 191 (1 0 1 1 1 1 1 1) to second 74595. Then Q7 Q6 Q5 Q4 Q3 Q2 Q1 Q0 of second 74595 becomes 1 0 1 1 1 1 1 1. This will turn on a, b, c and dp segments of seventh common cathode seven segment display and turn off all other seven segment displays as shown in the following image. When a, b, c and dp segments of a seven segment display is on "7." will be displayed in the seven segment display.

After displaying these, arduino will send 255 (1 1 1 1 1 1 1 1) to the second 74595 to turn off all the seven segment displays. Use of this function will be more clear, when you try to turn on more than one seven segment display at a time.