bbcmicrobit / micropython

Port of MicroPython for the BBC micro:bit
https://microbit-micropython.readthedocs.io
Other
603 stars 284 forks source link

music.pitch latches when music.stop occours on a different pin #661

Open rhubarbdog opened 5 years ago

rhubarbdog commented 5 years ago

I have this program which plays 440Hz on pin2. I stop pin0 with misic.stop(). The short note playing on pin2 latches. latch03.py.txt

dpgeorge commented 5 years ago

The music module can only handle playing music on one pin at a time, it's not supported to mix different pins in calls to play/pitch/stop/etc.

For the test script attached above, what happens is that the PWM is started on pin2 and then music.stop() stops the music subsystem and cancels the PWM on pin0. But pin2 continues to have PWM output on it and will never be turned off (unless it's used again) because the music subsystem is now idle.

I don't think anything really needs to be fixed here. Rather the docs could be updated to mention this, that you must use the same pin for all subsequent calls to the music module.

rhubarbdog commented 5 years ago

Why isn't the 12 millisecond time not expiring on ubit.pin2?

dpgeorge commented 5 years ago

Why isn't the 12 millisecond time not expiring on ubit.pin2?

Because when music.stop() is called it stops everything related to music, including the timeout for pin2. So there is never any event which stops PWM on pin2.