so i am working on a project which needs a lots of bit manipulation and shifting out the bits to control the pins of shift registers individually.
So i am using 2 shift registers daisy chained with 16 LEDS. Now, what i want is that, i want to control the LEDs individually just by shifting out the bits
here is what i tried
first Attempt
int latchPin = 4; // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 5; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 3; // Data pin of 74HC595 is connected to Digital pin 4
byte leds=0b1000000000000001; // byte has 16 bits
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
updateShiftRegister();
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
Does not work! the 2nd shift register seems to be copying the first shift register which i don't want
In second attempt, i tried the masking method with HEX data type. Here is it.
int latchPin = 4; // Latch pin of 74HC595 is connected to Digital pin 5
int clockPin = 5; // Clock pin of 74HC595 is connected to Digital pin 6
int dataPin = 3; // Data pin of 74HC595 is connected to Digital pin 4
byte leds=0xFFFF & 0x8001; // used hex masking method
// 0xFFFF = 1111111111111111
// 0x8001 = 1000000000000001
// After & it should be 1000000000000001
void setup()
{
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}
void loop()
{
updateShiftRegister();
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
}
This too makes same effect like the attempt 1 above.
Now here is what i want and need...
byte leds = 0b1000000000000001
/* As you can see the index 0 and index 15 of the byte led
is set 1 or high which should produce +ve to the 15th pin of first register and 8th pin of second register.
but whenever i try this, it seems that one of the register is copying another one.
So, is there any way to shift out bits to control the shift register outputs individually?
if yes then please give a clear example code with a clear explanation.
if no then, please suggest me some alternative ways which can be used in the same way i want , of course with example code and explanation.
Schematic: arduino.cc/en/Tutorial/Foundations/ShiftOut
Thank You so much for your precious time.
Looking forward to your replies .
:)