I'm using the 74HC959 shift register with my 4x4x4 cube. When I run my code it will light up pin 6-0 then 7 when I do it one by one. I have it set to go through pin 7-0 but it seem to be pushing 7 to the end. Anyone might know whats I'm doing wrong.
int dataPin = 11;
int clockPin = 12;
int latchPin = 8;
int cat[] = {10, 9, 7, 6}; //4 layers
byte data;
byte dataArray[8];
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
for (int i = 0; i < 4; i++)
{
pinMode(cat[i], OUTPUT);
digitalWrite(cat[i], HIGH);
}
//Using Hex decimal
dataArray[0] = 0x80; //1000 0000
dataArray[1] = 0x40; //0100 0000
dataArray[2] = 0x20; //0010 0000
dataArray[3] = 0x10; //0001 0000
dataArray[4] = 0x08; //0000 1000
dataArray[5] = 0x04; //0000 0100
dataArray[6] = 0x02; //0000 0010
dataArray[7] = 0x01; //0000 0001
}
void onebyone()
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 8; j++)
{
digitalWrite(cat[i], LOW);
data = dataArray[j];
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, data);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(100);
delay(100);
delay(100);
digitalWrite(cat[i], HIGH);
}
}
}
void loop()
{
onebyone();
}
// the heart of the program
void shiftOut(int dataPin, int clockPin, byte dataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
//for each bit in the byte myDataOut?
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>0; i--)
{
digitalWrite(clockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if (dataOut & (1<<i))
{
pinState= 1;
}
else
{
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(dataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(clockPin, 1);
}
}