The problem I've been having is a little weird. I'm trying to set up audio for my Arduino project and have been playing around with the example included in the IDE. The problem is whenever I try to make the array of notes go into PROGMEM, it makes the outputted note higher than the one I put in. I don't want it to do that. In case it is relevant, the code I have is as follows:
#define tuneSize 2
// notes in the melody:
const int melody[tuneSize] PROGMEM /*This is what's screwing it up*/= {
NOTE_AS3, 0
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[tuneSize] = {
6, 16
};
void setup() {
// no need to repeat the melody.
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < tuneSize; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(8, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(8);
}
}
(Pitch.h can be found in the Arduino example tab under digital)
My circuit has an 8 ohm resistor on pin 8. That's it.
The only thing I can think is that since the PROGMEM is slower, the data doesn't get to the speakers as fast thus making the output weird. Does anyone know how to fix this issue? Also, just having it on SRAM is not ideal because I'm working with a display and the lib it uses uses a lot of SRAM.