I have just started using a 74HC595 IC and want to be able to change a single value (bit) of the byte value without changing any other value in the byte, for example:
const uint8_t LED_0 = 0b00000001;
This will turn of all LED's except LED 0 (depending on the Most / Least Significant Bit order).
What I was thinking of doing in order to retain each bit value, is to place every bit value into an array e.g:
int seq[] = {0b,0,0,0,0,0,0,0,1};
If and when a pin on the 74HC595 changes I can easily change the value in the array to either 1 or 0.
The following procedure writes the byte to the IC:
void updateShiftRegister( const uint8_t value )
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, value );
digitalWrite(latchPin, HIGH);
}
The function is then called in this manner:
updateShiftRegister( LED_0 ); // led 0 on, other leds off
How can I combine the seq array above, to be able to pass all the values in the array to my procedure ?
I have looked at sprintf and String.concat but I am not entirely sure that is the way to go. I honestly doubt if the sprintf function should even be a consideration.
If a better / simplified method exist, please do not hesitate to educate me on that.
Regards, Tino