0% found this document useful (0 votes)
11 views

arduino_code

The document provides an example of controlling a 7-segment display using an Arduino Uno and a shift register. It includes code that defines the necessary pins, an array for the digits 0-9, and a loop function that displays each digit sequentially with a one-second delay. The setup function configures the pins as outputs, allowing for proper communication with the display.

Uploaded by

Emin Halilovic
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

arduino_code

The document provides an example of controlling a 7-segment display using an Arduino Uno and a shift register. It includes code that defines the necessary pins, an array for the digits 0-9, and a loop function that displays each digit sequentially with a one-second delay. The setup function configures the pins as outputs, allowing for proper communication with the display.

Uploaded by

Emin Halilovic
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Here is an example of how you can control a 7-segment display using an Arduino Uno

and a shift register:

const int dataPin = 2; // Data pin of the shift register


const int latchPin = 3; // Latch pin of the shift register
const int clockPin = 4; // Clock pin of the shift register

// An array of bytes representing the digits 0-9 on the 7-segment display


const byte digits[] = {
0b00111111, // 0
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
0b01100110, // 4
0b01101101, // 5
0b01111101, // 6
0b00000111, // 7
0b01111111, // 8
0b01101111 // 9
};

void setup() {
// Set the data, latch, and clock pins as outputs
pinMode(dataPin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop() {
// Loop over the digits 0-9
for (int i = 0; i < 10; ++i) {
// Shift the digit out to the shift register
shiftOut(dataPin, clockPin, MSBFIRST, digits[i]);

// Latch the data to the 7-segment display


digitalWrite(latchPin, HIGH);
digitalWrite(latchPin, LOW);

// Wait for one second


delay(1000);
}
}

This code defines the pins of the shift register and an array of bytes representing
the digits 0-9 on the 7-segment display. In the setup function, it sets the data,
latch, and clock pins as outputs.

In the loop function, it loops over the digits 0-9, shifts each digit out to the
shift register, latches the data to the 7-segment display, and waits for one
second. This will cause the 7-segment display to show each of the digits 0-9 in
sequence, with a one-second delay between each digit.

You might also like