hey yall, I want my robot to play 2 different kinds of music:
the first kind is always played on start up, and its format is exactly the same as in Buzzer1 example, with the MELODY_LENGTH, note[] and duration[] arrays like in the example.
In my main function, I have :
while(currentIdx!=MELODY_LENGTH) // run over and over again
{
if (currentIdx < MELODY_LENGTH && !is_playing())
{
play_note(note[currentIdx], duration[currentIdx], 15);
currentIdx++;
}
}
stop_playing();
just like in the example Buzzer1 and this one works perfectly. However, I am trying to have the robot play another piece of music in a specific function, when called. For this new piece of music, I have the same setup except for every variable and arrays, I added a “2” at the end to its name. I thus have a MELODY_LENGTH2, a note2[], and a duration2[]. In my function, it’s currently set up as
unsigned char currentIdx2;
void checkDead(){
currentIdx2=0;
if (health<=0){
clear();
while(currentIdx2!=MELODY_LENGTH2) // run over and over again
{
print("x");
if (currentIdx2 < MELODY_LENGTH2 && !is_playing())
{
print("x");
play_note(note2[currentIdx2], duration2[currentIdx2], 15); // overwrite any left over characters
currentIdx2++;
}
}
stop_playing();
while(1);
}
}
The print statements are for debugging, and I’ve experimented with commenting and uncommenting certain print statements, and I’ve determined that while the outer “print” statement works, the inner “print” doesn’t print anything. Additionally, I tried to comment the “if” statement out, but nothing gets played still.
Anyone have any idea?