Make a list of the file names, then randomize the order in which they are accessed.
Since a random number generator will occasionally give you repeats, the usual way is to "shuffle" the order of the list, then go through it in order. Look up "shuffle array" for the method.
Thank you for your suggestion but it doesn't quite apply to my question.
Here is are a few lines from the program (sketch) I had referred to..........
tft.setRotation(2); // portrait
tft.fillScreen(random(0xFFFF));
drawSdJpeg("/Baboon40.jpg", 0, 0); // This draws a jpeg pulled off the SD Card
delay(2000);
Where it calls for ("/Baboon40.jpg", 0, 0) , I cant find a way to make it call for a random .jpg on the SD card rather than a seperate call for each .jpg on the SD card.
With this piece of script below, it does not require knowing file names, it just displays one after another ...............
File file;
File root = SD.open("/");
if(!root){
Serial.println("Failed to open root directory");
return;
}
file = root.openNextFile(); // Opens next file in root
while(file)
{
if(!file.isDirectory())
{
drawSdJpeg(file.name(), 0, 0); // This draws a jpeg pulled off the SD Card
delay(4000);
}
file = root.openNextFile(); // Opens next file in root
}
Yes, the drawSdJpeg function expects a string, so you need to create a string with the number in it plus the .jpg extension. For example:
char filename [20]; // 19 chars max + terminating null
int i = 42;
itoa(i,filename,10); // Put string version of a number in filename, number base 10
strcat(filename, ".jpg"); // add .jpg to end of string
drawSdJpeg(filename, 0, 0);
You could use a switch--case scheme too: a 'random' number would be the case and that would result a filename call, without having to rename your files.
Hello there runaway_pancake,
Going with your suggestion, it would mean a Case (line) for every jpg file on the sd card.
If the sd card has 25 jpg's on it, that would be 25 individual case lines.
Correct me if I am wrong with that assumption.