Hello, I have a question, I am building a project where I need many buttons, so I used two chips: the 74ch165 and 74ch595 to detect 64 buttons. But I think I am losing efficiency in my project for doing this, so my question arises ... Is there a chip that has these two chips together to be able to manipulate 64 buttons? (Instead of having 2 chips that waste space and some memory in my code).
You can look at the Microchip MCP23017 (I2C ) and MCPS17 (SPI). 2x8 pins, you can use one set for the inputs and one set for the outputs.
I think that there are libraries for them but they will also use code space.
But I think I am losing efficiency in my project for doing this
Thinking is not enough And without seeing your code we can not even judge. If you want to post your code and if you haven't read How to use this forum - please read - Website and Forum - Arduino Forum yet, please read the link and pay specific attention to point #7 about posting code.
64 buttons is a matrix of 8x8, that are 16 I/O pins. I think you already have that when you use just one '165' and just one '595'.
They could be stored as bytes, so you need 64 bytes. You can pack them in bits, then you need 8 bytes. When using a struct with bit field, the RAM usage will be lower but the code size will increase.
I see no problem with hardware and software. Two chips for 64 buttons is efficient. A shift register is very efficient in software because no I2C library is needed.
Use an Arduino Mega and drop all additional chips. No code for shifting bits in and out, all buttons immediately accessible as a matrix or individual buttons.
I only wonder how you want to debounce the buttons. There exist chips that scan and debounce a button matrix, also handle multiple buttons down at the same time, roll over and more.
Wire the output and input shift registers as an SPI daisy chain with output reg first. Even if you don't use the SPI library you can beat I2C speed.
With SPI wiring you open the latch and send the next 8 bits (one at a time) to fill the output and at the same time the 8 bits in the input shift reg are pushed to the Arduino pin (one at a time, the same time one bit is sent) to read so you get output sent and input to read at the same time (SPI is bi-directional). And then you close the latch to put the 8 data bits you sent onto the output shift reg pins and at the same time it reads the input shift reg pins into the internal bits until the latch is opened again.
You don't even need the SPI library to do this but it'd be faster and use less CPU.
But for reading <= 64 buttons you don't need anywhere so much speed since there's a human behind the buttons.