I got 6 Shift Register 74HC165 connected together.
I need to convert these bit data from the 6 74HC164 ics to controll Leds.
uint64_t oldOptionSwitch = 0; // previous state of all the inputs
uint64_t optionSwitch = 0;
for( int i=40; i>=0; i-=8)
{
optionSwitch |= ((uint64_t) ReadOne165()) << i;
}
for( int i = 0; i<48; i++)
{
if( bitRead( optionSwitch, i) != bitRead( oldOptionSwitch,i))
{
//Serial.println( "Read Data:");
//if( i < 10)
// Serial.print( " ");
Serial.print( i);
Serial.print( " is now ");
Serial.println( bitRead( optionSwitch, i) == 0 ? "Released" : "Pressed");
}
}
oldOptionSwitch = optionSwitch;
byte ReadOne165()
{
byte ret = 0x00;
// The first one that is read is the highest bit (input D7 of the 74HC165).
for( int i=7; i>=0; i--)
{
if( digitalRead( SerData) == HIGH)
bitSet( ret, i);
digitalWrite( PCLK, HIGH);
delayMicroseconds( pulseWidth);
digitalWrite( PCLK, LOW);
}
return( ret);
}
What I need help with is how to split the "optionSwitch" to be able to set LEDs to High or Low depending on what button is pressed.
I was thinking like
int LED1
int LED2
...and so on...
I know
Led 1 is bit nr 47 of 48.
Led 2 is bit nr 46 of 48.