在PROGMEM中为arduino UNO连接字符串

时间:2022-07-11 20:36:23

I am trying to create a list of wavefile names soundList to play through an adafruit WAV shield ontop an arduino UNO. Since these file names are never going to change, and I am running out of sRam, I'd like to store them in PROGMEM but I get an error:

我正在尝试创建一个波形文件名列表soundList,通过adafino WAV盾牌在arduino UNO上播放。由于这些文件名永远不会改变,而且我的sRam用完了,我想将它们存储在PROGMEM中,但是我收到一个错误:

invalid operands of types 'const char*' and 'const char [5]' 
to binary 'operator+'

Am I not able to concatenate strings in PROGMEM? I don't understand why.

我无法在PROGMEM中连接字符串吗?我不明白为什么。

for (int i = 1; i < 19; ++i)
  {
    const char soundList[i] PROGMEM = "Track" + i + ".WAV";
    return soundList;
  }

Also I am having a hard time then reading the wavefiles out of soundList?

此外,我很难从soundList中读取wavefiles?

pgm_read_word(&(soundList[i])));

any words of wisdom?

任何智慧的话语?

1 个解决方案

#1


A for loop is a runtime operation. You cannot perform runtime operations that assign to a PROGMEM variable since the variable will be stored in (read-only at runtime) flash.

for循环是运行时操作。您无法执行分配给PROGMEM变量的运行时操作,因为变量将存储在(运行时只读)闪存中。

But since the only variable part is the number, store the other two parts in flash and create the filename at runtime.

但由于唯一的可变部分是数字,因此将其他两个部分存储在flash中并在运行时创建文件名。

#define FILEPREFIXLEN 5
char fileprefix[] PROGMEM = "Track";
#define FILESUFFIXLEN 4
char filesuffix[] PROGMEM = ".WAV";
#define FILEMIDLEN 2

 ...

char filename[FILEPREFIXLEN + FILEMIDLEN + FILESUFFIXLEN + 1];
// Read fileprefix into filename, append number, append filesuffix

#1


A for loop is a runtime operation. You cannot perform runtime operations that assign to a PROGMEM variable since the variable will be stored in (read-only at runtime) flash.

for循环是运行时操作。您无法执行分配给PROGMEM变量的运行时操作,因为变量将存储在(运行时只读)闪存中。

But since the only variable part is the number, store the other two parts in flash and create the filename at runtime.

但由于唯一的可变部分是数字,因此将其他两个部分存储在flash中并在运行时创建文件名。

#define FILEPREFIXLEN 5
char fileprefix[] PROGMEM = "Track";
#define FILESUFFIXLEN 4
char filesuffix[] PROGMEM = ".WAV";
#define FILEMIDLEN 2

 ...

char filename[FILEPREFIXLEN + FILEMIDLEN + FILESUFFIXLEN + 1];
// Read fileprefix into filename, append number, append filesuffix