m3pi play tune

I have the m3pi. Can I play still play a tune? This is what tried.

In m3pi.h, I added this.

int play(char* text, int length);

In m3pi.cpp, I added this.

void m3pi::play(void) {
    _ser.putc(DO_PLAY);

And this:
int m3pi::play (char* text, int length) {
    _ser.putc(DO_PLAY);
    _ser.putc(length);
    for (int i = 0 ; i < length ; i++ {
        _ser.putc(text[i];
    }
    return(0);
}

And this:

{ "play", rpc_method_caller<char, m3pi, &m3pi::play> },

No sure if all this is correct or what to do next.

Want to play “>g32>>c32”;
In the 3pi, this went into PROGMEM and called by: play_from program(welcome);

In m3pi.h, this was already written. So I figured play could be used in the m3pi.
#define DO_PLAY 0xB3

Don

Hello, donde.

Did it work? It looks like your code is correct, though you don’t need to have an RPC call, unless you are using a wireless interface that supports that. I made a version of the m3pi library that implements play, along with various other little fixes & additions, and it looks exactly the same as yours except I made the return type be void.

- Ryan

Hi RyanTM,
No, however I did try it, but didn’t compile. I’m still trying to refresh my C++ knowledge. And get stuck easily.

Anyway, thanks for the entries in both m3pi.cpp and m3pi.h for play() function. I’m going to try it. Now, how would I set up a tune. like the “welcome” or “go” in the line follower program, and call it? I’m using the 3pi as slave with mbed plugged into expansion board.
Is this original line for the 3pi added? const char welcome[] PROGMEM = ">g32>>c32"
And: play_from_program_space(welcome);
You can see how confused I still am!

By the way, did manage to use Timer() to stop robot after 35 seconds. and DigitalIn to stop robot in it’s tracks using Sharp 10cm distance sensor still attached. Next, I’ll spin it around and go back the other way. About what I did a couple years ago with just the 3pi.

Thanks, donde

Hey RyanTM,

I figured it out and music works fine!

I put this before main()
char* go = “L16 cdegreg4”; (Charge!)

And this after main()
m3pi.play(go, 13);

Of course with your super help in the m3pi library!

Thanks again,
donde