I have a project that has 5x 74HC595 shift registers daisy chained together. Looking for someone to help me write code to do:
- Prompt user to enter a value between 1-40. [This is to correspond to the 40 outputs of the 5x shift registers].
- Entered value then turns on the respective shift register output. For example, if '3' is entered, the 3rd output is enabled (all other outputs are turned off). If '25 is entered' the 25th output is enabled (all other outputs are turned off). If '40' is entered, the 40th output is turned off.
- If 'x' is entered, all outputs are turned off.
If '40' is entered, the 40th output is turned off.
Should that be 40th turned on?
Apologies! Yes that was a typo. The 40th would be turned on if '40' would be entered.
This shift register library allows individual control of outputs by number. Use the library or look into the source code to see how it is done.
There many ways. The 595 is a natural as an SPI device. You can use a SPI library.
Set up an array of 5 bytes. Make it all zeros at first. When the user enters a number, set the appropriate bit in the array. Then one SPI transfer can send all the data to your registers.
There are examples of how to connect the chip to the SPI port. It's 3 wires: MOSI, ~SS and SCK plus ground. You can ignore MISO.
Thanks all! I have figured it out