Go Down

Topic: Working with array of strings, PROGMEM question (Read 2 times) previous topic - next topic

Elso

Thank you very much indeed guys for sharing your knowledge and opinion.
I can see I am simply scratching the surface of the Progmem and strings, I will solder together an new mini OLED tonight and will see if everything works correctly.

So far I have been only compiling to check that everything works, strange enough Arduino will always give me the same randomly calculated names and last names, is that normal? I mean it puts together names and last names once, then if I unplug it and plug it back either some minutes later or the day after, it gives me back names and last names with the same order it did before, as if it can only ramdomly calculate names and last names once.

Any ideas about it?

Thanks!

Elso

Krodal

The random function starts with a seed and will produce the same numbers every time.

To start with a different seed, use : http://arduino.cc/en/Reference/RandomSeed
You could read noise from an analog input, or the light from an ldr, or the time from a RTC, and use that for the seed.


grossman

Example to work with PROGMEM.

Code: [Select]
const char PROGMEM message[]=        "String in flash";

Code: [Select]
String getFlashStr(const char PROGMEM varMessage[]) {
char c;
String msg; 

while( c= pgm_read_byte(varMessage++) ) {
msg+= c;
}

return msg;
}


Code: [Select]
char buffer[16];
getFlashStr(message).toCharArray(buffer, 16);

Go Up