hi paul.....made the changes to the code and using the hex representations for the patters now.....unfortunately the cube is still WIP so i thought of doing some debugging using Serial prints. The updated code is here:
#include <avr/pgmspace.h> // allows use of PROGMEM to store patterns in flash
#include <SPI.h>
#define CUBESIZE 4
#define PLANESIZE CUBESIZE*CUBESIZE
#define PLANETIME 1111 // time each plane is displayed in us -> 100 Hz refresh
#define TIMECONST 20 // multiplies DisplayTime to get ms - why not =100?
#define LATCHPIN 10
// LED Pattern Table in PROGMEM - last column is display time in 100ms units
// TODO this could be a lot more compact but not with binary pattern representation
PROGMEM prog_uint32_t PatternTable[] = {
// blink on and off
0x0000ffff,0xffffffff,0xffffffff,0xffffffff, 1,
0xffff0000,0xffffffff,0xffffffff,0xffffffff, 1,
// this is a dummy element for end of table (duration=0) aka !!!DO NOT TOUCH!!!
0xffffffff,0xffffffff,0xffffffff,0xffffffff, 0,
};
/*
** Defining pins in array makes it easier to rearrange how cube is wired
** Adjust numbers here until LEDs flash in order - L to R, T to B
** Note that analog inputs 0-5 are also digital outputs 14-19!
** Pin DigitalOut0 (serial RX) and AnalogIn5 are left open for future apps
*/
int PlanePin[] = {
16, 17, 18, 19};
// initialization
void setup()
{
int pin; // loop counter
pinMode(LATCHPIN, OUTPUT);
// set up plane pins as outputs (active LOW)
for (pin=0; pin<CUBESIZE; pin++) {
pinMode( PlanePin[pin], OUTPUT );
}
SPI.begin();
SPI.setBitOrder(MSBFIRST);
Serial.begin(9600);
}
// display pattern in table until DisplayTime is zero (then repeat)
void loop()
{
// declare variables
unsigned long PatternBuf[PLANESIZE]; // saves current pattern from PatternTable
int PatternIdx;
byte DisplayTime; // time*100ms to display pattern
unsigned long EndTime;
int plane; // loop counter for cube refresh
int patbufidx; // indexes which byte from pattern buffer
// Initialize PatternIdx to beginning of pattern table
PatternIdx = 0;
// loop over entries in pattern table - while DisplayTime>0
do {
// read pattern from PROGMEM and save in array
memcpy_P( PatternBuf, PatternTable+PatternIdx, PLANESIZE );
PatternIdx += PLANESIZE;
// read DisplayTime from PROGMEM and increment index
DisplayTime = pgm_read_byte_near( PatternTable + PatternIdx++ );
// compute EndTime from current time (ms) and DisplayTime
EndTime = millis() + ((unsigned long) DisplayTime) * TIMECONST;
// loop while DisplayTime>0 and current time < EndTime
while ( millis() < EndTime ) {
for (plane=0; plane<CUBESIZE; plane++) { // loop over planes
digitalWrite(LATCHPIN, LOW); //take latchpins low to load data to '595
SPI.transfer(PatternBuf[plane]); //shift out 4-bytes for the current plane
Serial.println("Value");
Serial.println(PatternBuf[plane], DEC);
digitalWrite(LATCHPIN, HIGH); //take latch pin high to display data
digitalWrite( PlanePin[plane], HIGH ); //activate current plane
Serial.println("Plane");
Serial.println(PlanePin[plane]);
delayMicroseconds( PLANETIME ); // delay PLANETIME us
digitalWrite(PlanePin[plane], LOW); //de-activate current plane
delay(1000);
} // for plane
} // while <EndTime
}
while (DisplayTime > 0); // read patterns until time=0 which signals end
}
I think i understand why i keep getting the same value whether i print in HEX/DECIMAL/BINARY for both the patterns for the first plane....my question is, is this going to work as expected meaning the zeros will get loaded to the shift registers in the proper order (in the first case 16- zeros to one 595 and 16- ones to the other one and then the opposite the second time). Also is there a way to print the zeros to the serial monitor to make it easier to debug?