Hi all.
I set the array to store the image path, and try to print out the path, got rebooting, why?
esp32s3 at arduino 1.8.19.
Thanks
Adam
char *ImagepathA[5][100] = {};
char *ImagepathB[100] = {};
int i = 0;
// ImagepathA[5][0]= "/newFolder1/image1";
// ImagepathA[5][1]= "/newFolder2/image2";
/// ImagepathA[5][2]= /newFolder3/image3;
/// ImagepathA[5][3]= /newFolder4/image4;
/// ImagepathA[5][4]= /newFolder5/image5;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
delay(5000);
Serial.println("setup!");
ImagepathA[5][0] = "/newFolder1/image1";
ImagepathA[5][1] = "/newFolder2/image2";
/// ImagepathA[5][2]= /newFolder3/image3;
/// ImagepathA[5][3]= /newFolder4/image4;
/// ImagepathA[5][4]= /newFolder5/image5;
ImagepathB[0] = "/newFolder1/image11";
ImagepathB[1] = "/newFolder2/image22";
/// ImagepathA[5][2]= /newFolder3/image3;
/// ImagepathA[5][3]= /newFolder4/image4;
/// ImagepathA[5][4]= /newFolder5/image5;
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < 2; i++) {
Serial.print("ImagepathA[5]["); Serial.print(i); Serial.print("]=");
Serial.println(ImagepathA[5][i]);
}
for (int i = 0; i < 2; i++) {
Serial.print("ImagepathB["); Serial.print(i); Serial.print("]=");
Serial.println(ImagepathB[i]);
}
delay(2000);
}
error:
setup!
ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x8 (TG1WDT_SYS_RST),boot:0xb (SPI_FAST_FLASH_BOOT)
Saved PC:0x420069db
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fce3808,len:0x44c
load:0x403c9700,len:0xbd8
load:0x403cc700,len:0x2a80
entry 0x403c98d0
shanren:
why?
At least because array indices go from zero 0 to one less than the dimension.
ImagepathA[5][0] = "/newFolder1/image1";
There is no row 5, row 4 is the last valid row number.
Wait - @shanren ? This comes as news now? Surely you've come across this by now.
a7
Do you indeed want to store 500 filenames? Or do you want to store 5 filenames each having a maximum of 100 characters?
b707
June 28, 2024, 5:21am
4
The asterisk is superficial in both cases
I think it depends on what is needed. 5*100 pointers to a filename or 5 filenames.
Do I see that wrong?
J-M-L
June 28, 2024, 12:10pm
6
If file paths are constant you could define them as
const char * imagePath[] = {
"/newFolder1/image11",
"/newFolder1/image22",
"/newFolder1/image33",
"/newFolder1/image44",
"/newFolder1/image55",
};
And print them out as
for (const char * path : imagePath) {
Serial.println(path);
}
I like to store 5 filenames each having a maximum of 100 characters. don't what's the right writing.
Get rid of the asterisk in front in char *ImagepathA[5][100] = {}; and use strcpy (you will need to do that inside a function (e.g. setup() ) to copy a filename to a variable.
Further pay attention to the earlier comments about indexing.
Or follow @J-M-L 's example above.
Thanks.
the paths are not constant. what I like to make is an electronic picture frames, this is just basic, design to show picture one by one and be able to show back the last shown one at any time by a backward button.
even more, I may add pictures any time and to show them?
J-M-L
June 28, 2024, 4:20pm
12
where are the pictures stored ? SD card or flash ?
J-M-L
June 29, 2024, 7:08am
14
So you expect the user to be able to swap the card (and reboot ?) and the code should be able to find all the pictures on the SD card and present them.
Is that the intended use case scenario?
Thanks.
to print or to get the path to do show back is headache for now.
as to add new pictures is just an idea, seems not easy?
I found an example here:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char * strs[0][3];
strs[0][0] = "string 1";
strs[0][1] = "string 2";
strs[0][2] = "string 3";
printf("String in 0 0 is : %s\n", strs[0][0]);
printf("String in 0 1 is : %s\n", strs[0][1]);
printf("String in 0 2 is : %s\n", strs[0][2]);
system("pause");
return 0;
}
how to make the serial number 0 1 2 parameterizeļ¼