Lesson 110-1: 74HC595 chip code 1/6: Walking light
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, we control the direction of rotation of a stepper motor using the keyboard on our computer via the serial monitor.
373-Arduino code for 74HC595 chip code 1/6: Walking light
语言: C++
/*
This is Arduino code for 74HC595 chip code 1/8: Walking light
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
original code source:
https://docs.sunfounder.com/projects/3in1-kit-v2/en/latest/basic_project/ar_shiftout_led.html
*/
const int DATA_DS_PIN14 = 10; //Pin connected to DATA_DS_PIN14 of 74HC595
const int LATCH_STCP_PIN12 = 11;//Pin connected to ST_CP of 74HC595
const int CLOCK_SHCP_PIN11 = 12;//Pin connected to SH_CP of 74HC595
int datArray[] = {B00000000, B00000001, B00000011, B00000111, B00001111, B00011111, B00111111, B01111111, B11111111};
void setup ()
{
Serial.begin(9600);
Serial.println("Code 0: 74HC595 2 digit display driver");
pinMode(LATCH_STCP_PIN12 ,OUTPUT);
pinMode(CLOCK_SHCP_PIN11,OUTPUT);
pinMode(DATA_DS_PIN14,OUTPUT);
}
void loop()
{
for(int num = 0; num <=8; num++)
{
digitalWrite(LATCH_STCP_PIN12 ,LOW); //ground ST_CP and hold low for as long as you are transmitting
shiftOut(DATA_DS_PIN14,CLOCK_SHCP_PIN11,MSBFIRST,datArray[num]);
//return the latch pin high to signal the chip that it
//no longer needs to listen for information
digitalWrite(LATCH_STCP_PIN12 ,HIGH); //pull the ST_CP to save the data
delay(2000); //wait for a second
}
}
资源与参考
-
外部
文件📁
没有可用的文件。