• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Individual pin control to dual on shift register (74HC595)

Q&A Forum › Category: ESP32 › Individual pin control to dual on shift register (74HC595)
0 Vote Up Vote Down
ALEXANDRE RPEREIRA asked 4 years ago

https://medium.com/@tiemenwaterreus/driving-16-leds-using-only-three-pins-of-an-arduino-3a6b1f60bc2c

My Schematic is like above

Hi , this program work fine to one register 74HC595, How can I  control two 74HC595 inside this?

const int latchPin = 27;
const int clockPin = 14;
const int dataPin = 23;
int i = 25;
byte leds = 0;
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
Serial.begin(115200);
Serial.println(“setup”);
}
void loop() {
if (Serial.available() > 0) {
int inByte = Serial.read();
switch (inByte) {
case ‘a’:
i = 0;
break;
case ‘b’:
i = 1;
break;
case ‘h’:
i = 7;
break;
case ‘j’:
i = 9;
break;
case ‘L’:
i = 10;
break;
default:
i = 25;
}
}
if ( i == 9) {
bitSet(leds, 0);
bitSet(leds, 1);
bitSet(leds, 2);
bitSet(leds, 3);
bitSet(leds, 4);
bitSet(leds, 5);
bitSet(leds, 6);
bitSet(leds, 7);
bitSet(leds, 8);
updateShiftRegister();
}
if ( i == 10) {
bitClear(leds, 0);
bitClear(leds, 1);
bitClear(leds, 2);
bitClear(leds, 3);
bitClear(leds, 4);
bitClear(leds, 5);
bitClear(leds, 6);
bitClear(leds, 7);
bitClear(leds, 8);
updateShiftRegister();
}
if ( i == 0) {
bitSet(leds, 0);
updateShiftRegister();
Serial.println(“0 on”);
}
if ( i == 1) {
bitSet(leds, 1);
updateShiftRegister();
Serial.println(“1 on”);
}

if ( i == 7) {
bitSet(leds, 7);
updateShiftRegister();
Serial.println(“7 on”);
}

}

Question Tags: 74HC595
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 4 years ago

Hi.

I think this tutorial covers what you are looking for: https://www.arduino.cc/en/Tutorial/Foundations/ShiftOut

Let me know if you need further help.

Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.