Hackster is hosting Hackster Cafe: Open Hardware Summit. Watch the stream live on Friday!Hackster is hosting Hackster Cafe: Open Hardware Summit. Stream on Friday!
PCBX
Published

Arduino-Controlled Dual 7-Segment LED Counters

Unlock creativity with Arduino-Controlled Dual 7-Segment LED Counters! Perfect for projects, displays, and learning electronics effortlessly

BeginnerFull instructions provided180

Things used in this project

Story

Read more

Schematics

tab-2024-11-8_16_06_dCx7oyRgwd.gif

circuit_AwxbkYqIQ5.png

Code

Arduino-Controlled Dual 7-Segment LED Counters

Arduino
// Define pins
const int dataPin = A5;    // The D1 pin of the shift register is connected to pin A5 of the Arduino
const int clockPin = A4;   // The clock input pin of the shift register is connected to pin A4 of the Arduino
const int resetPin = A3;   // The reset pin of the shift register is connected to pin A3 of the Arduino

// Common cathode 7-segment display characters
byte numbers[] = {
    0x3F, // 0
    0x06, // 1
    0x5B, // 2
    0x4F, // 3
    0x66, // 4
    0x6D, // 5
    0x7D, // 6
    0x07, // 7
    0x7F, // 8
    0x6F  // 9
};

void setup() {
    pinMode(dataPin, OUTPUT);
    pinMode(clockPin, OUTPUT);
    pinMode(resetPin, OUTPUT);
}

void loop() {
    for (int i = 0; i < 10; i++) {
        displayNumber(i, (i + 1) % 10);
        delay(1000);
    }
}

void displayNumber(int num1, int num2) {
    digitalWrite(resetPin, LOW); // Reset shift register
    digitalWrite(resetPin, HIGH);
    
    //Send data to the first 7-segment display
    shiftOut(dataPin, clockPin, MSBFIRST, numbers[num1]);
    
    // Send data to the second 7-segment display
    shiftOut(dataPin, clockPin, MSBFIRST, numbers[num2]);
}

void shiftOut(int value) {
    for (int i = 0; i < 8; i++) {
        digitalWrite(dataPin, (value & (1 << (7 - i))) ? HIGH : LOW);
        digitalWrite(clockPin, HIGH);
        digitalWrite(clockPin, LOW);
    }
}

Credits

PCBX
33 projects • 10 followers
Customer Success: Your one-stop solution for PCB and PCBA services, plus component sourcing. Enjoy FREE online simulation and EDA.
Contact

Comments

Please log in or sign up to comment.