ELEGOO MEGA · LESSON 27
74HC595 and Segment Display
Count from 9 down to 0 on a single common-cathode seven-segment display.
Map stored digit bits to physical display segments through a shift register.
Parts List
- ELEGOO Mega 2560 R3 is a 5 V ATmega2560 AVR board with many I/O pins and four hardware UARTs for control systems with several peripherals. Long ELEGOO-branded Mega PCB with USB-B and barrel connector, ATmega2560 marking, extended side headers and a large double-row digital header at the end. Read printed Mega labels; its SPI hardware placement is not the same numeric pins as an Uno.
- A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. USB-A plug and square USB-B plug. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.
- An 830-contact solderless breadboard joins inserted leads through hidden spring strips so circuits can be rebuilt without solder. Full-size rectangular board, center channel, numbered five-hole terminal groups and side power rails. Counted contact holes are not component units.
- 74HC595 accepts eight bits serially and latches them onto eight parallel logic outputs, expanding output control with a few GPIO lines. 16-pin DIP marked 74HC595/74HC595N with notch or pin-one dot. HC and HCT variants have different input thresholds.
- A bare 1-digit seven-segment LED package shows numeric values using shaped LED segments. Black single-numeral package with many leads.
- 1 kΩ resistor provides a fixed opposition to current. Signal current limiting and transistor base drive is a common use when its unverified power and tolerance limits fit the circuit. Small axial body with one wire at each end. Find the labeled value compartment and measure an isolated loose part with a meter; the shared inventory image is a form reference.
- 100 nF nonpolar ceramic capacitor stores electric-field energy. Local IC decoupling and short high-frequency supply disturbances are appropriate uses when voltage and circuit requirements are checked. Small non-polar disc, often marked 104; 104 means 100 nF, not 104 pF. Read the value and rating rather than estimating from body size.
- Male-to-male jumper leads make removable point-to-point connections for low-current prototype signals. Pins at both ends; count individual leads rather than ribbon groups. Check intact insulation and snug contacts before use.
Assembly
- Disconnect USB; identify the display as a compatible common-cathode part.
- Use the original layout with 1 kΩ for each of the eight segment resistors and add 100 nF across the IC supply.
- Keep both common-cathode pins 3 and 8 at GND; reconnect USB.

Reviewed connections
| From | To | Note |
|---|---|---|
| Mega D2,D3,D4 | IC 14 DS,12 ST_CP,11 SH_CP | MCU numbers are not IC terminal numbers |
| IC Q0..Q7 | Through one 1 kΩ each to display a,b,c,d,e,f,g,dp | Display pins 7,6,4,2,1,9,10,5 |
| Display commons 3 and 8 | GND | Common cathode only |
| IC 16/10 → 5 V; 8/13 → GND; 100 nF 16↔8 | Power, MR, OE | Pin 9 Q7′ open |
Source-reviewed wiring. Hardware not bench-tested; firmware uploads have not been performed.
Code
PlatformIO configuration
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600
#include <Arduino.h>
const uint8_t LATCH_PIN = 3;
const uint8_t CLOCK_PIN = 4;
const uint8_t DATA_PIN = 2;
// Bit 7 is segment a, then b,c,d,e,f,g,dp. LSBFIRST moves bit 7 into Q0.
const uint8_t DIGITS[10] = {0b11111100,0b01100000,0b11011010,0b11110010,0b01100110,
0b10110110,0b10111110,0b11100000,0b11111110,0b11100110};
// This function uses digit as an array index, then latches the complete pattern at once.
void sevenSegWrite(uint8_t digit) {
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, LSBFIRST, DIGITS[digit]);
digitalWrite(LATCH_PIN, HIGH);
}
void setup() {
pinMode(LATCH_PIN, OUTPUT); pinMode(CLOCK_PIN, OUTPUT); pinMode(DATA_PIN, OUTPUT);
}
void loop() {
// Count with a positive counter to avoid an unsigned byte wrapping below zero.
for (uint8_t digit = 10; digit > 0; --digit) {
delay(1000); sevenSegWrite(digit - 1);
}
delay(1000); // The executable source waits one extra second, despite a '4 seconds' comment.
}
Source: SOURCE_RECONCILED. Compile: COMPILE_VERIFIED. Hardware: NOT_TESTED. Upload: NOT_PERFORMED.
Expected behavior
Digits 9→0 appear about one second apart, with an extra one-second pause after zero. DP stays off. The first update follows an initial one-second wait.
Experiments & Challenges
- Change the countdown pause while preserving the digit-table indexes.
Troubleshooting
- Wrong shapes: verify Q0→a through Q7→dp and LSBFIRST; common-anode parts need a different circuit.