it's all 0's and1's..just like the shift register
you don't have to test the led-input because you already have the answer in the inputs, an "on" is a 1, an "off" is a 0, you so you don't need the internal int's for storing the inputs. all you have to do is then to place the 1's ond 0's in the right place. you do so by "bitshifting" to the left.
for instance led 3, if it's "on" the parameter (inlet_led3) is a 1(00000001), then you want to send the 595 a bit in the third place, (00000100). "inlet_led3<<2
" does that, it gives you the value bit shifted 2 steps to the left (>>
bit sifts to the right). every bit shift to the left doubles the value so x<<2
is actually the same as x*4
and x<<3
is the same as x*8
, only much faster because this is how computers work internally so the compiler doesn't have to do any complicated stuff, only pass the values.
right
then you add it up, say you enable led 1, 2, and 5, then you get 00000001, 00000010, and 00010000, add them together and you get 00010011 to send to the shift register
you can add by a simple + of course, but the "|" (bit OR) is simpler in this case and, same as bit shift, how the processor works.
last you bit shift the whole thing 0,8,16 or 24 steps to the left depending on which of the 4 shift registers is set in the "0to3" parameter.
actually, I realise my code was a little sloppy, the param_0to3 * 8
should of course be param_0to3<<3
, same thing but faster
outlet_out=(inlet_led1|(inlet_led2<<1)|(inlet_led3<<2)|(inlet_led4<<3)|(inlet_led5<<4)|(inlet_led6<<5)|(inlet_led7<<6)|(inlet_led8<<7))<<(param_0to3 <<3);
hope it's a little clearer now