Emilia Clarke Emilia Clarke - 1 year ago 76
Python Question

iRobot Create - Playing two songs

Here's my code:

import create
robot = create.Create(3)




The first song plays, but the second one won't...any ideas as to why?
This is being coded with the
Python interface to the iRobot Create:

Answer Source

Without seeing any documentation or source code, this is a wild guess, but…

I'll bet the playSongNumber function just sends the robot the play command, without waiting for it to finish, and when you send it a play command while it's already playing something, it ignores you.

If I'm right, then hopefully the API provides some way to wait until it's done. If it doesn't provide that, but it does provide a way to poll the current state, you can do that in a loop (sleeping briefly between each check) until it's done. If it doesn't even provide that, then you have to work out how long the song will take by counting the number of notes (or adding the durations, if one of the numbers in each of those pairs is a duration) and sleep that long.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download