In Arduino, I'm trying to combine the 8-bit binary numbers/strings from two PISO (parallel in - series out) shift registers into one 16-bit binary string. The binary numbers stored on a variable (switchVar1) with the shiftIn() command on Arduino switchVar1 = shiftIn(dataPin, clockPin);
switchVar1 was first defined by byte switchVar1 = 72;
.
I'm doing this so I can then read the binary string with the switch() function and do different combinations as I have 16 contacts/buttons where different combinations of all the 16 buttons will be defined so I need a string of 16-bit binary number.
Basically, I'm asking how to turn two 8-bit binary number arrays into one single array.
Keep in mind, I'm completely new to c++ so there might be some basic solution that I probably didn't think of.
It got figured out with thanks to everyone commenting. So I just did it like:
switchVar1 = shiftIn(dataPin, clockPin); switchVar2 = shiftIn(dataPin2, clockPin2); uint16_t switchVariable = switchVar1 | (switchVar2<<8);
as in I first created two, byte files and "shifted" the numbers on one (switchVar2) 8 steps to the left (to be literal) (with the <<
bitwise operator) and added both together with the bitwise OR operator (the pipe symbol |) in one uint16_t
variable type. Then I just read all the combinations with the switch() case
command.
(Also, I'm stupidly new to programming languages in general, and saying "arrays" was my bad.)