hey guys!
I am actually trying to create a digital clock using the 7 segment display, since its easier to see and more appealing to the eyes. Now before jumping straight into the clock I wanted to learn working with the 4 digit 7 segment display using the 74hc595 shift register (i am using a common anode type display).
I am controlling this display using 2 shift registers. the q7 (of 1st shift register) controls the 1st digit q0 of second controls the 2nd digit q1 controls the 3rd digit and q2 controls the 4th digit.
What I am trying to achieve now is to display numbers 0-9 in a manner that it displays one number 7 segment and the next number is displayed on the next. i.e 0 in the 1st digit, 1 in the second digit, so on 3 in the 4 th digit and 4 back on the 1st digit. In this sequence number 9 ends up on the second digit. Here is where the problem starts.
I want the next zero in the 3rd digit place and move on in the same patters, instead of the going back to the 1st digit. this is the code I have made up so far.
int latchPin = 2; //pin 12 on the 595
int dataPin = 3; //pin 14 on the 595
int clockPin = 4; //pin 11 on the 595
int shift = 128;
void setup() {
//Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
//0
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 64 );
digitalWrite(latchPin, HIGH);
delay(500);
//1
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 121);
digitalWrite(latchPin, HIGH);
delay(500);
//2
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 36);
digitalWrite(latchPin, HIGH);
//Serial.println("2 is printed");
delay(500);
//3
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 48);
digitalWrite(latchPin, HIGH);
delay(500);
//4
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 25);
digitalWrite(latchPin, HIGH);
delay(500);
//5
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 18);
digitalWrite(latchPin, HIGH);
Serial.println("5 is printed");
delay(500);
//6
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 4 + 2);
digitalWrite(latchPin, HIGH);
delay(500);
//7
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 8 + 120);
digitalWrite(latchPin, HIGH);
delay(500);
//8
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift + 0);
digitalWrite(latchPin, HIGH);
delay(500);
//9
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 64 >> 8 );
shiftOut(dataPin, clockPin, MSBFIRST, shift * 2 + 16);
digitalWrite(latchPin, HIGH);
delay(500);
shift = shift * 4;
}
I am able to display uptill 9 and the next zero and 1 in the 3rd and 4th digits but there after the numbers just shift outside the scope and nothing is displayed. since the count goes beyond 1024, like 2048, 4096, and so on, i need an idea to convert 2048 so that i can correspond it to 1st digit , similarly 4096 to second digit. and so on. I hope I have made my problem clear! any help is appreciated!