TFT image loading

Hi

I'm completely new to programming and although I've made progress with this project, I'm now a bit lost, and looking for help. I think what I want to do is probably very simple, but I'm happy to be corrected if that's not the case. Basically, I want to display some bitmap images on a 128 x 160 TFT screen. I've got it to the point where I can read an image from an SD card and display it using

logo = screen.loadImage("image4.bmp");

I now need to be able to load different images based on a variable from elsewhere in the sketch. The actual image names can be just a number so .bmp

I discovered that I could define a character matrix and load say "4.bmp" into it and then get a correctly fetched and displayed image using

logo = screen.loadImage(character matrix name);

And here I run out of steam. How (or even can) I create file names in the format 'variable.bmp' and get the screen.loadimage function to accept them.

I hope that makes sense, and please bear in mind with any replies that I am completely new to this and old enough to be retired ... !

Thanks

How (or even can) I create file names in the format 'variable.bmp'

sprintf()

Thank you for your response. However, I was hoping for something a little more than a one word answer. As I thought I had been careful to point out, I am a total novice at programming. I am new. I am a learner. I'm old now and sadly not as quick-witted as I once was. I tried looking up sprintf() but everything I found on it went way over my head. I don't expect anyone to just write code for me. I've been doing my best so far and was fairly pleased with how far I'd managed to get, but by the same token I was hoping to at least get some detailed pointers on a help forum as to how to put the code together. That is how I will learn and not have to ask the same thing again.

Sorry if I'm being bothersome to your forum ...

What have you tried, with sprintf?

It writes a formatted string to an array. So, you need an array:

char fileName[16];

You want the string to contain the value of some variable, so you need a variable:

int fileNumb = 14;

Then, you call sprintf() with the array, a format string, and the variable(s):

sprintf(fileName, "%d.bmp", fileNumb);

Print fileName, and see what it contains. Change the format string, and see what happens. Only by actually trying something, and seeing what happens will cause you to learn anything.

Thank you. I think that will probably help. I have not tried anything with sprintf yet as I did not understand just what it did. I think maybe I do now. I am honestly a complete novice at this. So far, I have achieved what I have by taking example code and modifying and experimenting with it, but I am at a bit of a loss when new ideas and use of functions that I have not seen used practically, are introduced. I'll see how I get on when I get back to it and let you know

I created an array of 8 characters. I created a variable and set it to a value of 1. I called sprintf in the manner you suggested, and then did a print of my array contents to the serial monitor. And Lo ! It returned

"1.bmp"

so a result. I should now be able to incorporate this into my main code to create the ultimately wanted results on the TFT screen.

Thank you for your help