Arduino Uno 7-Segment Display
Embedded
Electronics
Implementation…
/*
Control a group of 8x LEDs using a 74HC595 Shift Register
- Pin 1-7,15 output to LEDs + 220ohm resistors
- Pin 8 == GND connect to ground
- Pin 10 == MR, Master Reclear, connect to 5V
- Pin 13 == OE, Output enable, connect to ground
- Pin 16 == VCC connect to 5V
*/
const int msec = 1000;
// Output pins connected to the 74HC595 shift register
const int dPin = 4; // goes to pin 14 == DS, Serial data input
const int lPin = 5; // goes to pin 12 == ST_CP, Storage register clock pin (latch pin)
const int cPin = 6; // goes to pin 11 == SH_CP, Shift register clock pin
unsigned int num[] = {
0b11111100, // 0
0b01100000, // 1
0b11011010, // 2
0b11110010, // 3
0b01100110, // 4
0b10110110, // 5
0b10111110, // 6
0b11100000, // 7
0b11111110, // 8
0b11100110, // 9
0b11101110, // A
0b00111110, // b
0b10011100, // C
0b01111010, // d
0b10011110, // E
0b10001110, // F
0b00000001 // DP
};
// Represents the state of the shift register chip
// Pins 1-7,15 == Q0-Q7, Output Pins
= 0;
byte leds
// Print bit representation of a byte
void serialPrintByte(byte b) {
;
byte i// loop bit shift
for (byte i = 0; i < 8; i++) {
.print(b >> i & 1, BIN);
Serial}
.println("");
Serial}
void txRegisterState(byte state) {
// Signal the register to read from the data pin
(lPin, LOW);
digitalWrite.println("Ground latch pin while transmitting data");
Serial// Use the data pin to send a byte to the register bit-by-bit
// - Right most LSB (Least Significant Bit)
(dPin, cPin, LSBFIRST, state);
shiftOut// Signal the register to set all its output pins
(lPin, HIGH);
digitalWrite.print("LEDs bit state: ");
Serial(state);
serialPrintByte.println("Signal end of transmission");
Serial}
void setup() {
.begin(9600);
Serial(dPin, OUTPUT);
pinMode(lPin,OUTPUT);
pinMode(cPin,OUTPUT);
pinMode}
void loop() {
int n;
for(n = 0; n <= 17; n++)
{
(num[n]);
txRegisterState(msec);
delay}
}