Introduction
At some point in time, you may need to use more pins than is available on the Arduino. One way to add additional inputs and outputs is to use shift registers. A shift register is a form of sequential logic, composed of a group of flip-flops. A flip-flop is a circuit that has two states, you can also think of it as a basic storage element that can store a binary digit.
In this guide, we will learn how to connect 8 LEDs to the Arduino while only using 3 digital pins instead of 8!
Complete this guide to understand the basics of using a shift register.
Tools
-
-
-
-
-
-
-
-
-
-
-
-
-
int latchPin = 4; int clockPin = 3; int dataPin = 2; byte leds = 0; void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { leds = 0; delay(500); for (int i = 0; i < 8; i++) { bitSet(leds, i); digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, leds); digitalWrite(latchPin, HIGH); delay(500); } }
-
int latchPin = 4; int clockPin = 3; int dataPin = 2; byte leds = 0; void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); Serial.begin(9600); } void loop() { leds = 0; delay(500); for (int i = 0; i < 8; i++) { Serial.println(leds); bitSet(leds, i); digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, leds); digitalWrite(latchPin, HIGH); delay(500); } }
-
int latchPin = 4; int clockPin = 3; int dataPin = 2; byte leds = 0; void setup() { pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); Serial.begin(9600); } void loop() { Serial.println(leds, BIN); bitSet(leds, 1); bitSet(leds, 7); digitalWrite(latchPin, LOW); shiftOut(dataPin, clockPin, LSBFIRST, leds); digitalWrite(latchPin, HIGH); delay(500); }