Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Arduino Code for a Controlling a Common Cathode 4 Digit 7 Segment Display using Two Shift Registers
int latchPin = 2; //pin 12 on the 595
int dataPin = 3; //pin 14 on the 595
int clockPin = 4; //pin 11 on the 595
//D1 = 256, D2 = 512, D3 = 1024, D4 = 2048
int D1 = 3584;
int D2 = 3328;
int D3 = 2816;
int D4 = 1792;
void setup() {
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop() {
//A
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D1+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D1+119);
digitalWrite(latchPin, HIGH);
delay(1);
//n
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D2+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D2+84);
digitalWrite(latchPin, HIGH);
delay(1);
//t
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D3+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D3+120);
digitalWrite(latchPin, HIGH);
delay(1);
//o
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D4+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D4+92);
digitalWrite(latchPin, HIGH);
delay(1);
/*//0
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D1+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D1+63);
digitalWrite(latchPin, HIGH);
delay(1000);
//1
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D2+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D2+6);
digitalWrite(latchPin, HIGH);
delay(1000);
//2
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D3+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D3+91);
digitalWrite(latchPin, HIGH);
delay(1000);
//3
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D4+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D4+79);
digitalWrite(latchPin, HIGH);
delay(1000);
//4
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D1+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D1+102);
digitalWrite(latchPin, HIGH);
delay(1000);
//5
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D2+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D2+109);
digitalWrite(latchPin, HIGH);
delay(1000);
//6
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D3+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D3+125);
digitalWrite(latchPin, HIGH);
delay(1000);
//7
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D4+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D4+7);
digitalWrite(latchPin, HIGH);
delay(1000);
//8
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D1+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D1+127);
digitalWrite(latchPin, HIGH);
delay(1000);
//9
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D2+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D2+103);
digitalWrite(latchPin, HIGH);
delay(1000);
//DP
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D3+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D3+128);
digitalWrite(latchPin, HIGH);
delay(1000);
//A
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D4+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D4+119);
digitalWrite(latchPin, HIGH);
delay(1000);
//b
digitalWrite(latchPin, LOW); //to avoid fluttering of led when you send data
shiftOut(dataPin, clockPin, MSBFIRST, D1+64 >> 8);
shiftOut(dataPin, clockPin, MSBFIRST, D1+124);
digitalWrite(latchPin, HIGH);
delay(1000);*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.