A 7-segment display with 4 digits is an electronic component used to display numerical information. Each digit consists of 7 LEDs arranged in a figure-8 pattern, allowing for the display of numbers 0-9. This component is widely used in digital clocks, electronic meters, and other devices that require a simple, numeric display.
Parameter | Value |
---|---|
Operating Voltage | 3.3V - 5V |
Current per Segment | 10-20mA |
Power Consumption | 140mW (max) |
Number of Digits | 4 |
Segment Configuration | Common Anode or Common Cathode |
Operating Temperature | -40°C to +85°C |
Pin Number | Description |
---|---|
1 | Digit 1 Common Anode |
2 | Segment E |
3 | Digit 2 Common Anode |
4 | Segment D |
5 | Segment C |
6 | Digit 3 Common Anode |
7 | Segment DP (Decimal Point) |
8 | Segment B |
9 | Segment A |
10 | Digit 4 Common Anode |
11 | Segment F |
12 | Segment G |
Pin Number | Description |
---|---|
1 | Digit 1 Common Cathode |
2 | Segment E |
3 | Digit 2 Common Cathode |
4 | Segment D |
5 | Segment C |
6 | Digit 3 Common Cathode |
7 | Segment DP (Decimal Point) |
8 | Segment B |
9 | Segment A |
10 | Digit 4 Common Cathode |
11 | Segment F |
12 | Segment G |
// Define segment pins
const int segmentPins[] = {2, 3, 4, 5, 6, 7, 8, 9}; // A, B, C, D, E, F, G, DP
// Define digit pins
const int digitPins[] = {10, 11, 12, 13}; // Digit 1, 2, 3, 4
// Digit patterns for numbers 0-9
const byte digitPatterns[10] = {
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111 // 9
};
void setup() {
// Set segment pins as outputs
for (int i = 0; i < 8; i++) {
pinMode(segmentPins[i], OUTPUT);
}
// Set digit pins as outputs
for (int i = 0; i < 4; i++) {
pinMode(digitPins[i], OUTPUT);
}
}
void loop() {
// Display the number 1234
displayNumber(1234);
}
void displayNumber(int number) {
for (int i = 0; i < 4; i++) {
int digit = number % 10; // Get the last digit
number /= 10; // Remove the last digit
// Set the digit pattern
setDigitPattern(digitPatterns[digit]);
// Activate the current digit
digitalWrite(digitPins[i], LOW);
delay(5); // Short delay for multiplexing
digitalWrite(digitPins[i], HIGH);
}
}
void setDigitPattern(byte pattern) {
for (int i = 0; i < 8; i++) {
digitalWrite(segmentPins[i], (pattern >> i) & 0x01);
}
}
By following this documentation, you should be able to effectively use a 7-segment display with 4 digits in your projects. Whether you are a beginner or an experienced user, this guide provides the necessary information to get started and troubleshoot common issues.