Hello,
I'm currently writing a program that reads an array of times and frequencies to play a song using a buzzer. However, I'm having some trouble reading data from the array, which is stored in PROGMEM. Here is the code:
const uint16_t m1durs[] PROGMEM = {
0,0,0,0,0,0,0,227,240,467,480,707,720,947,.......,95280,95399,95520,96887,
}
m1size = sizeof(melody1) / sizeof(pgm_read_word_near(&melody1[0]));
Serial.println(m1size);
placeholderduration = pgm_read_word_near(&m1durs[m1size-1]);
Serial.println(placeholderduration);
As you can see, I'm trying to read the last value in the array. However, while m1size prints out correctly (~940 numbers), placeholderduration prints out a value of around 31000--far from the actual value that should be read.
This weird behavior didn't occur with a different array I had used earlier, though, so I'm really at a loss. Is there something I'm doing wrong?