Robots not dancing while WAV song plays

110 views Asked by At

I am working on a project that requires a group of Scribbler 2s to dance at the start of playing a wav file and stop at the end of the file.

(This is not the full code, but rather me testing how to do it so I can apply it to the larger code.)

from Myro import *
from winsound import*
from time import *

def playSong():
    s=PlaySound('C:\Python34\cantHoldUs.wav',SND_FILENAME)
    sleep(30)
    s.PlaySound(None,SND_FILENAME)

while playSong()==True:
    motors(-1,1)   

The song plays and ends, but the robot does not move. Can anyone tell me how?

1

There are 1 answers

15
Adib On

I'd recommend restructuring your code to something with a While Loop since it's cleaner and easier to control:

from time import *

# Play the song
s=PlaySound('C:\Python34\cantHoldUs.wav',SND_FILENAME)

# Start the timer so we can identify when to stop
starttime = time()

# Use a while loop with a True statement until we decide to break it
while True:
    # Make that robot dance!
    motors(-1,1)

    # Check the current time
    stop_time = ((time() - starttime))

    # Stop when 30 seconds is hit
    if stop_time > 30:
        s.PlaySound(None,SND_FILENAME)
        break

    sleep(1)