I have been trying to make a music player that runs off of an uno using tone, with notes stored in arrays that progresses every time that the loop statement in arduino runs (set with a delay of 10). The problem I am having is that it is just outputting static. I have tried multiple different methods all with the same results. Any help or advice is very appreciated.
#include "note.h"
void playSong(song music[], int pin);
void beats(int timer);
void nextPhrase();
void playPhrase(note music[], int pin);
void endPlaying();
boolean isPlayingMusic();
int delayAmount;
const int dottedWholeNote = (((10000 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int wholeNote = (((6666 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int dottedHalfNote = (((5000 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int halfNote = (((3333 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int dottedQuarterNote = (((2500 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int quarterNote = (((1666 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int dottedENighthNote = (((1250 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int eighthNote = (((833 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int dottedSixteenthNote = (((625 / delayAmount) / delayAmount) * delayAmount) * 1.3;
const int sixteenthNote = (((416 / delayAmount) / delayAmount) * delayAmount) * 1.3;
int noteCount = 0;
int nextNote = 0;
int currentPhrase = 0;
int currentNote = 0;
boolean isPlaying = false;
//Ancient Guardian Music
note phrase0[] = {(BN4, eighthNote), (BN3, sixteenthNote), (EN3, sixteenthNote), (FNS3, sixteenthNote), (BN3, sixteenthNote), (EN3, sixteenthNote), (BN3, sixteenthNote), (AN4, sixteenthNote), (BN3, sixteenthNote), (FNS3, sixteenthNote), (BN3, sixteenthNote)};
note phrase1[] = {(BN4, sixteenthNote), (BN3, sixteenthNote), (FNS3, sixteenthNote), (BN3, sixteenthNote), (EN3, sixteenthNote), (BN3, sixteenthNote), (AN3, sixteenthNote), (BN3, sixteenthNote), (GN3, sixteenthNote), (BN3, sixteenthNote), (AN4, sixteenthNote), (BN3, sixteenthNote)};
note phrase2[] = {(BN3, eighthNote), (AN3, eighthNote), (FNS3, eighthNote), (EN3, eighthNote), (AN4, eighthNote), (FNS3, eighthNote)};
note phrase3[] = {(EN3, wholeNote + quarterNote), (GN3, halfNote), (AN4, dottedHalfNote), (CN3, wholeNote + dottedHalfNote), (FN3, dottedWholeNote)};
note phrase4[] = {(AN3, dottedQuarterNote), (BN3, dottedQuarterNote), (EN3, eighthNote), (DN3, quarterNote), (BN4, eighthNote), (AN4, eighthNote), (GN3, eighthNote), (DN3, eighthNote), (EN3, eighthNote), (FNS3, eighthNote), (CN3, eighthNote), (DN3, eighthNote), (EN3, eighthNote), (FNS2, eighthNote), (AN3, eighthNote), (DN2, eighthNote), (DNS2, eighthNote), (EN2, eighthNote), (DN4, eighthNote), (DNS4, eighthNote), (EN4, eighthNote), (FN3, eighthNote), (FN3, eighthNote), (REST, eighthNote), (FN3, eighthNote), (REST, eighthNote), (FN3, eighthNote), (REST, eighthNote), (FN3, eighthNote), (REST, eighthNote), (FN3, eighthNote), (FN3, eighthNote), (FN3, eighthNote), (FN3, eighthNote)};
song guardianRobotMusic[] = {(phrase0, 1), (phrase1, 3), (phrase2, 72), (phrase3, 6), (phrase2, 4), (phrase4, 1)};
//************************************
void playSong (song music[], int pin) {
noteCount = noteCount + delayAmount;
if (currentPhrase < sizeof(music)) {
if (!isPlaying || noteCount == music[currentPhrase].phrase[nextNote].duration) {
tone(pin, music[currentPhrase].phrase[nextNote].noteTone, music[currentPhrase].phrase[nextNote].duration / 1.3);
nextNote++;
isPlaying = true;
} else if (nextNote >= sizeof(music[currentPhrase].phrase)) {
nextPhrase();
}
} else if (currentPhrase >= sizeof(music) && nextNote >= sizeof(music[currentPhrase].phrase)) {
endPlaying();
}
}
void beats (int timer) {
delayAmount = timer;
}
void nextPhrase () {
currentPhrase++;
nextNote = 0;
currentNote = 0;
}
void endPlaying () {
currentPhrase = 0;
nextNote = 0;
currentNote = 0;
}
code.zip (1.86 KB)