Hello all,
I know you're busy so I'll be brief, ish. I have an array of 16 solid state arrays which I want to drive with two 595 shift registers. I also have over 18 buttons, rotary encoders and switches which I'd like to use as inputs for them through three or more 4021 shift registers.
I have worked out how to read the pins of a single 4021 and I'm confident I can use the existing examples to work out how to read the pins of two or three more, so I don't think that's a problem at the moment. The part I'm struggling with is the code to set the outputs to the 595's if I need to have multiple pins high simultaneously as the corresponding buttons are pressed in a completely random pattern.
As far as I currently know, I can't shift out one byte for one pin then another byte for another pin without overwriting the byte currently stored in the register, so I'd have to code every possible combination of input presses and therefore every possible combination of pins high and low. Of course, this is ludicrous when you have potentially over 18 inputs and 16 outputs, and there must be a way to do this, but I can't find it on the internet or in my brain.
I'm guessing there's some kind of mathematical calculation for this or an automatically generating array trick (I did read about a method of generating an array then reading from it in Processing, actually, but I suspect doing that would fill the memory of the Arduino pretty quickly if I have all those combinations to do), but to be honest I've fallen behind in learning Arduino coding and have been concentrating more on learning the actual electronics. Plus I was in the bottom class for maths at school so I have no idea what I'm doing there, either.
Thanks for taking the time to read this and thank you in advance for any replies you might send my way.
Cheers,
Neema