Hi all, hope you can help. What is the correct way to read "HELLO2" from the code below?
prog_char hello[] PROGMEM =
{
"HELLO1"
"HELLO2"
"HELLO3"
};
Many thanks.
Hi all, hope you can help. What is the correct way to read "HELLO2" from the code below?
prog_char hello[] PROGMEM =
{
"HELLO1"
"HELLO2"
"HELLO3"
};
Many thanks.
Does that snippet even compile?
I don't get any errors apart from the line that says
sprintf_P(str1, hello[2]);
my full code below.
#include <avr/pgmspace.h>
prog_char hello[] PROGMEM =
{
"HELLO1"
"HELLO2"
"HELLO3"
};
void setup()
{
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial)
{
; // wait for serial port to connect. Needed for Leonardo only
}
}
void loop()
{
char str1;
sprintf_P(str1, hello[2]);
Serial.print(str1);
delay(5000);
}
Am wanting to have an array of strings and read them when i want. Just trying to learn about progmem.
prog_char hello[] PROGMEM =
{
"HELLO1"
"HELLO2"
"HELLO3"
};
This is what "hello" contains: "HELLO1HELLO2HELLO3" (a single C string)
If that's what you want, then it is easy to locate "HELLO2" - it starts at offset 6, and is 6 characters long.
It might be easier for you to store them as separate strings.
I have just noticed AWOL that my strings are not separate lol and thats what i want so i gues my code needs to be something like below
prog_char hello[] PROGMEM =
{
"HELLO1",
"HELLO2",
"HELLO3"
};
so how would i read the second string?
I have worked it out now with the code below.
#include <avr/pgmspace.h>
prog_char hello[3][7] PROGMEM =
{
"HELLO1",
"HELLO2",
"HELLO3"
};
void setup()
{
Serial.begin(9600);
while (!Serial)
{
;
}
}
void loop()
{
char str1[16];
sprintf_P(str1, hello[2]);
Serial.print(str1);
delay(5000);
}
I have worked it out now with the code below.
If that code is printing "HELLO2", something is wrong. That should be printing "HELLO3".