Hello,
The new issue I have is that the tone function does not work correctly. It plays the same tone, no matter what freq you give it. I took the melody and liquidcrystal example and made a nice little test program. I have a 4 row LCD and I Put up the 4 variables and watch them change. I added Tempo. They change and the tune plays but with the same tone.
I thought that the pitches.h was the problem so I change all the notes to Frequencies. The pitches.h was an attached tab in the example sketch and the following sketch.
GRYMG4_001
Vaccumdiode2 Mar 12 2011
Code (C++):#include "pitches.h"
#include <LiquidCrystal.h>
// creates a LiquidDisplay object with R/S, R/W and E on pins 8,9,10
// and data pins on port 2
LiquidCrystal myDisplay = LiquidCrystal(8,9,10,2);
//Tempo is the ms duration of a whole note dertermined by the Beats
// Per Minute BPM
int Tempo=1000;
// notes in the melody:
int freq[] = {
659, 659, 988, 988, 880, 784, 698, 659, 587, 880, 659, 698, 784, 880
};
// note durations: 1=whole, 2=half, 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2
};
// noteDot: 1=no Dot, 1.5=Dot
int noteDot[] = {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5
};
void setup() {
}
void loop() {
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 14; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = Tempo /4, eighth note = tempo/8, etc.
int noteDuration = Tempo/noteDurations[thisNote]*noteDot[thisNote];
tone(7, freq[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;
myDisplay.clear();
myDisplay.home();
myDisplay.print("thisNote a is: ");
myDisplay.setCursor(16, 0);
myDisplay.print(thisNote);
myDisplay.setCursor(0, 1);
myDisplay.print("Freq a is: ");
myDisplay.setCursor(16, 1);
myDisplay.print(feq[thisNote]);
myDisplay.setCursor(0, 2);
myDisplay.print("Duration a is: ");
myDisplay.setCursor(16, 2);
myDisplay.print(noteDuration);
myDisplay.setCursor(0, 3);
myDisplay.print("Between a is: ");
myDisplay.setCursor(16, 3);
myDisplay.print(pauseBetweenNotes);
delay(pauseBetweenNotes);
}
}
Thank you,
Vaccumdiode2