To display (1234) on 4-digit 7-segment display using Arduino uno 

 

Code:

#include <Arduino.h>

const int digitPins[] = {9, 10, 11, 12};
const int segmentPins[] = {2, 3, 4, 5, 6, 7, 8};

// Define the segments for digits 0-9 (Common-Cathode)
const byte digitSegments[10][7] = {
{1, 1, 1, 1, 1, 1, 0}, // 0
{0, 1, 1, 0, 0, 0, 0}, // 1
{1, 1, 0, 1, 1, 0, 1}, // 2
{1, 1, 1, 1, 0, 0, 1}, // 3
{0, 1, 1, 0, 0, 1, 1}, // 4
{1, 0, 1, 1, 0, 1, 1}, // 5
{1, 0, 1, 1, 1, 1, 1}, // 6
{1, 1, 1, 0, 0, 0, 0}, // 7
{1, 1, 1, 1, 1, 1, 1}, // 8
{1, 1, 1, 1, 0, 1, 1} // 9
};

//  ▄▄▄▄▄▄▄▄▄   ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄       ▄▄ 
// ▐░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░▌     ▐░░▌
//▐░█░█▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀▀▀  ▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░▌░▌   ▐░▐░▌
//▐░▌▐░▌    ▐░▌▐░▌               ▐░▌     ▐░▌          ▐░▌          ▐░▌          ▐░▌       ▐░▌▐░▌▐░▌ ▐░▌▐░▌
//▐░▌ ▐░▌   ▐░▌▐░█▄▄▄▄▄▄▄▄▄      ▐░▌     ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌          ▐░▌       ▐░▌▐░▌ ▐░▐░▌ ▐░▌
//▐░▌  ▐░▌  ▐░▌▐░░░░░░░░░░░▌     ▐░▌     ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌          ▐░▌       ▐░▌▐░▌  ▐░▌  ▐░▌
//▐░▌   ▐░▌ ▐░▌ ▀▀▀▀▀▀▀▀▀█░▌     ▐░▌     ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌          ▐░▌       ▐░▌▐░▌   ▀   ▐░▌
//▐░▌    ▐░▌▐░▌          ▐░▌     ▐░▌     ▐░▌          ▐░▌          ▐░▌          ▐░▌       ▐░▌▐░▌       ▐░▌
//▐░█▄▄▄▄▄█░█░▌ ▄▄▄▄▄▄▄▄▄█░▌ ▄▄▄▄█░█▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▄        ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░▌       ▐░▌
// ▐░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌▐░▌       ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌       ▐░▌
//  ▀▀▀▀▀▀▀▀▀   ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀  ▀         ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀         ▀
 
 

void setup() {
for (int i = 0; i < 4; i++) {
pinMode(digitPins[i], OUTPUT);
digitalWrite(digitPins[i], HIGH); // Turn off all digits initially
}
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
digitalWrite(segmentPins[i], LOW); // Turn off all segments initially (Common-Cathode)
}
}

void displayDigit(int digit, int value) {
for (int i = 0; i < 7; i++) {
digitalWrite(segmentPins[i], digitSegments[value][i]);
}
digitalWrite(digitPins[digit], LOW);
delay(5); // Adjust delay for brightness
digitalWrite(digitPins[digit], HIGH);
}

// ██████  ███████ ██ ███████ ███████     ██████  ██████  ███    ███ 
//██  ████ ██      ██ ██      ██         ██      ██    ██ ████  ████ 
//██ ██ ██ ███████ ██ █████   █████      ██      ██    ██ ██ ████ ██ 
//████  ██      ██ ██ ██      ██         ██      ██    ██ ██  ██  ██ 
// ██████  ███████ ██ ███████ ██      ██  ██████  ██████  ██      ██ 

void loop() {
int numberToDisplay = 4321;

for (int digit = 0; digit < 4; digit++) {
int digitValue = numberToDisplay % 10;
displayDigit(digit, digitValue);
numberToDisplay /= 10;
delay(0); // Display each digit for 1 second
}
}

 

 

 

 

osief.com
 osief.com
  osief.com
   osief.com
    osief.com
     osief.com
      osief.com

       osief.com
        osief.com
         osief.com
          osief.com
           osief.com
            osief.com
             osief.com

              osief.com
               osief.com
                osief.com
                 osief.com
                  osief.com

                   osief.com
                    osief.com
                     osief.com
                      osief.com
                       osief.com
                        osief.com

A 4-digit 7-segment display typically has multiple pins for connecting to a microcontroller or other control circuitry. The exact pinout can vary depending on the manufacturer and model of the display, but here’s a general overview of the common pins you might find:

  1. Common Anode or Common Cathode: 4-digit 7-segment displays come in two common types – common anode and common cathode. In a common anode display, all the anode pins for each segment are connected together, and you provide a positive voltage to light up a segment. In a common cathode display, all the cathode pins for each segment are connected together, and you provide a ground connection to light up a segment. You need to determine which type you have.
  2. Segment Pins: There are typically 7 segment pins for each digit, labeled “A,” “B,” “C,” “D,” “E,” “F,” and “G.” These pins correspond to the individual segments of each digit, and you control them to display the desired numbers or characters.
  3. Digit Pins: There are four pins (or more, depending on multiplexing) for selecting which digit you want to display. These are often labeled as “D1,” “D2,” “D3,” and “D4.” You activate one digit at a time in a sequential manner to display all four digits.
  4. Decimal Point Pin: If your display supports a decimal point, there might be an additional pin labeled as “DP” or “DOT” for controlling the decimal point.
  5. Common Pin: In common anode displays, there’s a common pin for each digit that connects to the anodes of all segments in that digit. In common cathode displays, there’s a common pin for each digit that connects to the cathodes of all segments in that digit.

Please refer to the datasheet or documentation provided by the manufacturer of your specific 4-digit 7-segment display to get the exact pinout and electrical characteristics for your display.

 

 

0sief