Lecture Topic 3.2.2 LED Binary Project
Lecture Topic 3.2.2 LED Binary Project
Seven segmented displays are great. They are pretty simple, don't take much power, and have a lot of
flexibility when it comes to displaying numbers. But setting aside 14 pins just to run it is such a pain. If
only there was a way to use them without sacrificing so many precious pins. Turns out there is! Shift
Registers are logical IC's that can hold or shift data sent into them. They only take up three pins.
This is the code for making the shift registers count from 0 to 99 and loop. Notice how the latch first has
to be set low, then shifted out, then set high again. The latch is what allows the registers to retain their
position in between clock cycles. The second digit comes first because it is sent into register 1 and then
shifted by 1 byte out to register 2 as digit one takes its place.
#define LATCH 4
#define CLK 3
#define DATA 2
//This is the hex value of each number stored in an array by index num
byte digitOne[10]= {0x6F, 0x09, 0x73, 0x3B, 0x1D, 0x3E, 0x7C, 0x0B, 0x7F,
0x1F}; byte digitTwo[10]= {0x7B, 0x11, 0x67, 0x37, 0x1D, 0x3E, 0x7C, 0x13, 0x7F,
0x1F};
int i;
void setup(){
pinMode(LATCH, OUTPUT);
pinMode(CLK, OUTPUT);
pinMode(DATA, OUTPUT);
}
void loop(){
for(int i=0; i<10; i++){ for(int j=0; j<10; j++){
digitalWrite(LATCH, LOW);
shiftOut(DATA, CLK, MSBFIRST, ~digitTwo[i]); // digitTwo
shiftOut(DATA, CLK, MSBFIRST, ~digitOne[j]); // digitOne
digitalWrite(LATCH, HIGH);
delay(500);
}
}
}