A simple example of how to use Arduino and two 8-bit shift registers to control two 7-segment LED displays to show numbers. By cycling through the numbers 0 to 9, you can observe the digits changing on the displays.
Pin DefinitionsThe code begins by defining the pins connected to the shift registers:
dataPin (Pin A5): This is the serial data input pin for the shift register.
clockPin (Pin A4): This is the clock input pin for the shift register.
resetPin (Pin A3): This is the reset pin for the shift register, used to clear the register before sending new data.
Display CharactersThe numbers array defines the hexadecimal codes for the digits 0 through 9 for a common cathode 7-segment display. These codes indicate which segments should be lit to display each digit.
Setup FunctionIn the setup function, all defined pins are set to output mode.
Loop FunctionThe loop function contains an infinite loop that calls the displayNumber
function to display two digits on the 7-segment displays, with each digit being displayed for 1 second (1000 milliseconds).
The displayNumber function takes two parameters, num1 and num2, which are the digits to be displayed on the two 7-segment displays. The function first resets the shift register by pulling the reset pin low and then high. It then sends the data for each digit to the corresponding shift register and locks it in with the latch pin.
ShiftOut FunctionThe shiftOut function is used to send a byte of data to the shift register. It loops through 8 times, sending each bit of the data byte to the data pin and toggling the clock pin to shift the data.
Comments
Please log in or sign up to comment.