So I have made my own basic RGB format with no alpha, one byte for R, one byte for G, one byte for B.
And my display is a 24x15 RGB LED matrix, so 360 x 3 = 1080 bytes per frame. I wrote a Java program to scale down video and store it in this tiny resolution. The display is multiplexed using 74hc595s to open the columns, and TLC5940s to sink the rows.
So my file format was a file with 100 frames, so it took up 108KB.
When I run the code below with 100 frames, it plays the video, and gets to about frame 60 at a regular pace, and then the frame processing counter speeds up, and every LED just flashes red for the last 40 frames.
Then the SD code opens the next file, and the video starts playing again.
So I thought maybe 100 frames was too much for the Arduino Mega, so I changed my file format to 30 frames per file. But now, it gets to about frame 15 or so, and then the frame processing counter speeds up, flashing red for the last 15 frames.
Bizarre. So it's as though my program just messes up quicker, since i gave it less work to do. Makes no sense.
Any idea what it might be??
I set up the SDFat with SoftSPI, where the chipSelect pin is the SS pin of my SD shield.
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) sd.initErrorHalt();
byte youtubebuffer[1080][3];
...
for (int numFiles = 1; numFiles < 20; numFiles++)
{
char buff[10];
sprintf( buff, "s_%d.dat", numFiles );
if (!myFile.open(buff, O_READ)) {
sd.errorHalt("opening s_0 for read failed");
}
Serial.println(buff);
int bytesRead;
byte r, g, b;
for (int frame = 0; frame < 30; frame++)
{
for(int x = 0; x < 1080; x++)
{
//each byte holds a value from 0-255
youtubebuffer[x][0] = myFile.read();
youtubebuffer[x][1] = myFile.read();
youtubebuffer[x][2] = myFile.read();
}
printBuffer(frame);
}
myFile.close();
Serial.write("Closed");
}
void printBuffer(int counter)
{
int r,g,b;
int ndx = 0;
for(int x = 0; x < 24; x++)
{
// Tlc.clear();
openCol(x);
for(int y = 0; y < 15; y++)
{
//each byte holds a value from 0-255
r = youtubebuffer[ndx][0] ;
g = youtubebuffer[ndx][1] ;
b = youtubebuffer[ndx][2] ;
int red = getRedSinkValue(y);
int green = red+1;
int blue = red+2;
if (r != 0)
{
Tlc.set(red, r <<2);
}
else
{
Tlc.set(red, 0);
}
if (g != 0)
{
Tlc.set(green, g <<2);
}
else
{
Tlc.set(green, 0);
}
if (b != 0)
{
Tlc.set(blue, b <<2);
}
else
{
Tlc.set(blue, 0);
}
ndx++;
// Serial.print(r);
// Serial.print(" ");
// Serial.print(g);
// Serial.print(" ");
// Serial.print(b);
// Serial.print(" ");
//Serial.println(ndx);
}
Tlc.update();
}
Serial.print(counter);
Serial.print("\n");
}