搜索代码

Lesson 110-3: Two-Digit LED Seven-Segment Display Using 74HC595

Lesson 110-3: Two-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 3: Two digits display

Now we learn how a single-digit display works. Please use the provided code below.

375-Arduino code for 74HC595 chip code 3/6: 2 chip with two digits seven-segment displays
语言: C++
/*
This is Arduino code for 74HC595 chip code 3/8: 2 chip with two digits seven-segment displays
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
*/
int CLOCK_SHCP_PIN11 = 12;//SHcp pin of 74HC595 
int LATCH_STCP_PIN12 = 11;//STcp pin of 74HC595 
int DATA_DS_PIN14 = 10;//ds pin of 74HC595 

#define DIGITS 2



byte segmentsBits[] =   {B00111111, //0
                   B00000110, //1
                   B01011011, //2
                   B01001111, //3
                   B01100110, //4
                   B01101101, //5
                   B01111101, //6
                   B00000111, //7
                   B01111111, //8
                   B01101111  //9
                  };

int digit1, digit2, digit3, digit4;

void setup() {
  Serial.begin(9600);
  Serial.println("Code 2: 74HC595 2 digit display driver");
  pinMode(CLOCK_SHCP_PIN11, OUTPUT);
  pinMode(LATCH_STCP_PIN12, OUTPUT);
  pinMode(DATA_DS_PIN14, OUTPUT);

   digitalWrite(CLOCK_SHCP_PIN11, LOW);
   digitalWrite(LATCH_STCP_PIN12, LOW);
   digitalWrite(DATA_DS_PIN14, LOW);

}

void loop() {
  long number = 18;
    digit2=number % 10 ;//18 gets 8
    digit1=(number / 10) % 10 ;//18 gets 1
    int digitBits =B11111110;
      digitalWrite(LATCH_STCP_PIN12, LOW);
      shiftOut(DATA_DS_PIN14, CLOCK_SHCP_PIN11, MSBFIRST, digitBits); 
      shiftOut(DATA_DS_PIN14, CLOCK_SHCP_PIN11, MSBFIRST, segmentsBits[ digit1]);
      digitalWrite(LATCH_STCP_PIN12, HIGH);    
     // Serial.print("Showing: ");Serial.println(digit1);
      delay(1);

      digitBits =B11111101;
      digitalWrite(LATCH_STCP_PIN12, LOW);
      shiftOut(DATA_DS_PIN14, CLOCK_SHCP_PIN11, MSBFIRST, digitBits); 
      shiftOut(DATA_DS_PIN14, CLOCK_SHCP_PIN11, MSBFIRST, segmentsBits[ digit2]);
      digitalWrite(LATCH_STCP_PIN12, HIGH); 
      //Serial.print("Showing: ");Serial.println(digit2);               
      delay(1);



}

文件📁

没有可用的文件。