As in the title, I'm trying to pass a Byte array from progmem to a Byte array in SRAM.
This is what i got so far:
byte zeigen [21] PROGMEM = // I also used prog_uchar, const byte and byte*(which gave me invalide conversion from int to byte* error, HL this line),
{
0x0, 0xFF, 0xFF, 0xFF,0xFE,0xFC, 0xF8, 0xF0,0xE0, 0xC0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE,0xFF, 0xFF,0xFF, 0x0}
;
byte buffer[21];
void setup()
{
strcpy(buffer, (byte*//also tried only byte and without anything))pgm_read_byte(&zeigen)); // byte, prog_uchar and const byte gave me a invalide conversion from byte* to char* error. i also tried pgm_read_word with the same result
}
void loop()
{
}
Why do i get the invalide conversion from int to byte*, and why is there a conversion from byte* to char*, and where? does strcpy only only take char arrays?
i already passed a char array with this method and it worked. An other method would be to read each byte individually with a for loop but that seems kinda ugly.
You should also look at exactly what pgm_read_byte() returns. There is a reason that the function takes an argument that defines where to store the value that is fetched from PROGMEM, rather than just returning the byte fetched from PROGMEM.
Copying the return value from pgm_read_xxx() to a string makes no sense.
Hm so i seems that most bytes are stored in the same place.
for(int i = 0; i <21; i++)
{
Serial.println( pgm_read_byte(konstante*));* } gives me * *12 12 64 12 12 12 148 12 12 64 64 64 64 64 64 64 12 12 224 12 12* * Is the adress even printable? How can i use this location given by the pgm_read_byte() to pass the byte? //edit: ok the solution is to reference each byte: ```
*prog_uchar konstante [21] PROGMEM = {0x0, 0xFF, 0xFF, 0xFF,0xFE,0xFC, 0xF8, 0xF0,0xE0, 0xC0, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE,0xFF, 0xFF,0xFF, 0x0};
byte Bytebuffer[21];
for(int i = 0; i <21; i++)
{
Bytebuffer[i] = pgm_read_byte(&konstante[i]);
}* ``` So to & takes the adress given by pgm_read_read() and passes the value stored at that adress to Bytebuffer*?*
bluebubble:
So to & takes the adress given by pgm_read_read() and passes the value stored at that adress to Bytebuffer*?* [/quote] Not quite. pgm_read_byte() takes the address of a byte in the program address space and returns the value of that byte. You would store the value in a plain old byte variable in SRAM - Bytebuffer [ i ] in your example. Your konstante array is stored in the program address space and &konstante[ i ] is returning the address (in the program address space) of the i'th element in that array.