unsigned long shiftdata = active_display[active_row]; // get row data for 25 leds
unsigned long shiftmask = 1;
for (byte i = 0; i < 32; i++) { // shift 32 bits (only 25 bits are wired up to cube) of data out for the 25 display columns
if (shiftdata & shiftmask) {
digitalWrite(dataPin, HIGH);
}
else {
digitalWrite(dataPin, LOW);
}
digitalWrite(clockPin, HIGH); // clock each bit into shift register
digitalWrite(clockPin, LOW);
shiftmask = shiftmask * 2; //right shift bit mask one bit
}
Well this is how to do it with hardware SPI:
unsigned long shiftdata = active_display[active_row]; // get row data for 25 leds
digitalWrite(pinSPI_SS, LOW); // Select chip.
SPI.transfer(shiftdata & 255); // Write first byte.
SPI.transfer((shiftdata>>8) & 255); // Shift second byte into first byte and write out first byte.
SPI.transfer((shiftdata>>16) & 255);
SPI.transfer((shiftdata>>24) & 255);
digitalWrite(pinSPI_SS, HIGH); // Deselect chip.
And here's a simpler method to do it in software:
unsigned long shiftdata = active_display[active_row]; // get row data for 25 leds
digitalWrite(pinShiftLatch, LOW); // Select chip
shiftOut(pinShiftData, pinShiftClock, MSBFIRST, shiftdata);
shiftOut(pinShiftData, pinShiftClock, MSBFIRST, shiftdata>>8);
shiftOut(pinShiftData, pinShiftClock, MSBFIRST, shiftdata>>16);
shiftOut(pinShiftData, pinShiftClock, MSBFIRST, shiftdata>>24);
digitalWrite(pinShiftLatch, HIGH); // Deselect chip
I don't know when the shiftout function became available so maybe you didn't have the option to use it though. And you don't need the & 255 on the shifted bits because the shiftout fucntion only shifts out the lower 8 bits of the int passed to it.
I also assume you're selecting the chip outside the function, but I included the code to do that here so others reading it wouldn't be confused about the need to do that.
And just for kicks, here's another way you could have done it manually:
unsigned long shiftdata = active_display[active_row]; // get row data for 25 leds
for (byte i = 0; i < 32; i++) { // shift 32 bits (only 25 bits are wired up to cube) of data out for the 25 display columns
if ((shiftdata>>byte) & 1) {
digitalWrite(dataPin, HIGH);
}
else {
digitalWrite(dataPin, LOW);
}
digitalWrite(clockPin, HIGH); // clock each bit into shift register
digitalWrite(clockPin, LOW);
}