*Σύντομα και στα Ελληνικά
Introduction
In this tutorial you will learn how to use a shift register (or serial to paralled controller). The shift register will give to your Arduino an additional 8 digital outputs, by using only 3 pins on your board
In this tutorial you will practice by using the shift register with Arduino uno to control 8 LEDs. |
What you will need - Hardware
For this tutorial you will need:
|
The Circuit
The connections are easy, see the image above with the breadboard circuit schematic.
You can find more info about IC here: datasheet |
The code
We will use example sketch from ShiftRegister74HC595.h library.
How it works:
How it works:
- sr.setAllHight(); Turn all LEDs on
- sr.setAllLow(); Turn all LEDs off
- sr.set(i, HIGH); Turn LED i on ( 0 < i < 7)
- uint8_t pinValues[] = { B10101010 };
- sr.setAll(pinValues); Binary to turn on 2nd,4th,6th and 8th LED
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /* ShiftRegister74HC595.h - Library for easy control of the 74HC595 shift register. Created by Timo Denk (www.simsso.de), Nov 2014. Additional information are available on http://shiftregister.simsso.de/ Released into the public domain. */ #include <ShiftRegister74HC595.h> // create shift register object (number of shift registers, data pin, clock pin, latch pin) ShiftRegister74HC595 sr (1, 2, 3, 4); void setup() { } void loop() { sr.setAllHigh(); // set all pins HIGH delay(500); sr.setAllLow(); // set all pins LOW delay(500); for (int i = 0; i < 8; i++) { sr.set(i, HIGH); // set single pin HIGH delay(2000); } // set all pins at once uint8_t pinValues[] = { B10101010 }; sr.setAll(pinValues); delay(5000); // read pin (zero based) uint8_t stateOfPin5 = sr.get(5); } |
Download the code from here and open it with Arduino IDE. Inside you will also find additional libraries.
|
|
You can make your own modifications to the code, for example, try to change line: uint8_t pinValues[] = { B10101010 }; with uint8_t pinValues[] = { B11001100 };
Well done!
You have successfully completed one more "How to" tutorial and you learned how to use a shift register ic with Arduino. I hope you liked this, let me know in the comments. You can also post photos with your circuit!