I'm shifting out 6 half bytes to three 595's.
1. Each time you call
shiftOut() It always shifts out eight bits.
2. So: if you have
three '595 devices connected in the usual manner, you need to call shiftOut
three times.
3. On Arduino, a variable whose data type is
byte always has eight bits.
4. So: if you want to shift the bits , say, 00110011, you can create a byte that has those bits and then call shiftOut. (See Footnote.)
5. If you have a byte whose bits are 00000011 and you want to make upper 4 bits equal to lower four bits:
byte x = B0011; // Same as if you had written byte x = B00000011;
.
.
.
x = (x << 4) | x; // Assumes upper four bits are zero
.
.
.
// If you don't know whether the upper four bits are zero and you want to make sure to throw them away
x = (x << 4) | (x & B00001111);
Regards,
Dave
Footnote:Arrays always start with index equal to zero, so your array elements have the following values:
Dig[0] = B0000; // Same as B00000000 or, simply, 0
Dig[1] = B0001; // Same as B00000001 or, simply, 1
Dig[2] = B0010; // Same as B00000010 or, simply, 2
DIg[3] = B0011; // Same as B00000011 or, simply, 3
.
.
.
Dig[9] = B1001; // Same as B00001001 or, simply, 9
So you don't need an array at all for these values, since the value of Dig[n] is, simply, n for n = 0, 1, ..., 9
However...
If you want to eliminate the necessity of having to use logical operations to duplicate the lower bits into the upper bits, you can define the elements of the array like this:
byte Dig[] = {
B00000000,
B00010001,
B00100010,
B00110011,
B01000100,
B01010101,
B01100110,
B01110111,
B10001000,
B10011001
};
Then in the loop, shift
Dig[ i ] three times to fill the three shift registers with that byte:
digitalWrite(latchPin, LOW)
shiftOut(dataPin, clockPin, MSBFIRST, Dig[i]);
shiftOut(dataPin, clockPin, MSBFIRST, Dig[i]);
shiftOut(dataPin, clockPin, MSBFIRST, Dig[i]);
digitalWrite(latchPin, HIGH)
So, with
i equal to 3, you will be sending B00110011 to each of the three shift registers.