Lesson 110-4: Single-Digit LED Seven-Segment Display Using 74HC595
This code is to introduce the 74HC595 to drive 8 LED lights and turn them on from 0 to 8 one by one while keeping each LED on. In Project 2: Single Digit Seven Segment Display Now we learn how a single-digit display works. Please use the provided code below.
374-Arduino code for 74HC595 chip code 2/6: Single digit display
语言: C++
/*
This is Arduino code for 74HC595 chip code 2/8: Single digit display
Build up to 8 digits Seven-Segment display using 74HC595 Shift Register
Watch full video instruction on YouTube https://youtu.be/xhPXovgFhso
resource page and wiring diagram https://robojax.com/RTJ394
Written and explained by Ahmad Shamshiri on https://youtube.com/@robojax
*/
/*
file: Lesson_74HC595_1_SevenSegment
This is part of the code to learn how to run multiple seven-segment displays using
74HC595 shift register IC.
March 16, 2024
*/
const int CLOCK_SHCP_PIN11 = 12;//SHcp pin of 74HC595
const int CLATCH_STCP_PIN12 = 11;//STcp pin of 74HC595
const int DATA_DS_PIN14 = 10;//ds pin of 74HC595
byte digits[] = {B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B10000111, //7
B01111111, //8
B01101111 //9
};
void setup ()
{
//set pins to output
pinMode(CLATCH_STCP_PIN12,OUTPUT);
pinMode(CLOCK_SHCP_PIN11 ,OUTPUT);
pinMode(DATA_DS_PIN14,OUTPUT);
}
void loop()
{
for(int num = 0; num <=8; num++)
{
digitalWrite(CLATCH_STCP_PIN12,LOW); //ground ST_CP and hold low for as long as you are transmitting
shiftOut(DATA_DS_PIN14,CLOCK_SHCP_PIN11 ,MSBFIRST,digits[num]);
//return the latch pin high to signal the chip that it
//no longer needs to listen for information
digitalWrite(CLATCH_STCP_PIN12,HIGH); //pull the ST_CP to save the data
delay(2000); //wait for a second
}
}
资源与参考
-
外部
文件📁
没有可用的文件。