Problem using play() function code with Baby Orangutan 328

I apologize in advance if the answer is somewhere in the forum, I did a search for play function and didn’t find any help.

I am trying to learn the libraries you guys provide (which are a great help for beginners like me, thank you so much) - I am reading and trying to run the examples described in your library document. I have a Baby Orangutan that I program using the Arduino IDE and your ISP programmer. I connected a buzzer on PB2/pin 10 and I know it works because I was able to run the sample code using playNote().

Since this was successful, I decided to move along to the next example. I removed all the code having to do with LCD and button since my board doesn’t have them and I uploaded the program to the board. All I get is a continuous beep, no notes, no changes, no interruptions, no stopping. I tried using both the notes string in PROGMEM and in RAM, I tried both play and playFromProgramSpace but none works right, like I said I only get one long beep.

I thought at some point that maybe play and playFromProgSpace don’t work on the Baby board but the lib docs say they should work (provided I have a buzzer, of course).

In one case the code looks like:

#include <OrangutanBuzzer.h>

OrangutanBuzzer buzzer;

#include <avr/pgmspace.h>

const char fugue[] PROGMEM = "! O5 L16 agafaea dac+adaea ......................";

void setup() {}

void loop()
{
    buzzer.playFromProgramSpace(fugue);
}

the other one I tried was:

#include <OrangutanBuzzer.h>

OrangutanBuzzer buzzer;

void setup() {}

void loop()
{
    buzzer.play("! V8 cdefgab>cbagfedc");
}

Is there anything I’m doing wrong? Maybe I missed something. I appreciate any help I can get. Thank you in advance!

Hello.

The OrangutanBuzzer play function is non-blocking, so to get good results you need to give it a chance to finish playing the notes before you call it again.

Try moving the code you have in loop() to setup().

–David

Thank you for your help, I will try to move it to setup and see what is happening.

Even if I am not sure I understand what you are saying, “give it a chance to finish playing the notes before you call it again.” I only called it once, in the loop, the call to play was the only line in the loop(). I mentioned I tried the other thing but that was a separate program not the same one.

Anyway, I will try, thank you!

The loop function is called an indefinite number of times (in a loop). The Arduino environment has some hidden code like this:

void main()
{
  setup();
  while(1)
  {
    loop();
  }
}

You are absolutely right, I should’ve thought of this. Sorry for being so dumb and thanks for your patience with me.