Closed microbit-carlos closed 3 years ago
@jaustin , @microbit-giles, @microbit-mark and I had a chat about this today and one thing that became clear is that it makes sense to move the enable()
/disable()
methods out of microbit.pin_speaker
into a new object instance called microbit.speaker
.
An important idea we discussed was to change the concept of the speaker being controlled by a pin and think of it as being a built-in feature:
play()
methods need to configure the speaker pin.pin_speaker
.Another thing to take in consideration is that any issues with the pin argument can be addressed in the documentation, but:
Current implementation of the pin
argument:
pin
arguments
play(Sound.HAPPY)
== play(Sound.HAPPY, pin=(pin_speaker, pin0))
play(Sound.HAPPY, pin=pin0)
pin0
with a different pin
play(music.PYTHON)
play(music.PYTHON, pin=pin2)
play(music.PYTHON, pin=(pin_speaker, pin2))
(pin0, pin1)
doesn't work?speaker.disable()
or change the pin argument value is not as clearSuggested change to the pin
argument:
pin
argument goes back to taking a single pin
play(Sound.HAPPY)
== play(Sound.HAPPY, pin=pin0)
play(Sound.HAPPY, pin=None)
Common uses cases:
microbit.speaker.disable()
music.play(music.PYTHON)
music.play(music.PYTHON, pin=None)
Does pin_speaker
still exist within MicroBitPin
in this scenario? And if not, does speaker move into the microbit
module? Or do both exist?
Is there a function to configure the default pin when no pin is specified?
Does
pin_speaker
still exist withinMicroBitPin
in this scenario? And if not, does speaker move into themicrobit
module? Or do both exist?
Yes, pin_speaker still exists, but without the enable/disable, and now there would be a speaker.enable() and speaker.disable().
Is there a function to configure the default pin when no pin is specified?
No, the default is for v1 compatibility, so if the users want to use a different pin they need to use the pin argument, as with V1.
Should speaker.enable/disable be speaker.on/off in line with MakeCode? We switched to on/off here to be more child friendly.
This is also in line with MicroPython radio.on/off and display.on/off. I don't think we have precedent for enable/disable
Discussed https://github.com/microbit-foundation/micropython-microbit-v2/issues/30#issuecomment-745980525 in standup and we should go with on/off for consistency and for translation. For note, MakeCode also uses true/false for the display so should we also be consistent there?
I probably wouldn't change a MakeCode block that's been available for years.
For the MicroPython speaker API, we should mirror display with on
, off
, and is_on
.
I think the whole 'led enable' block name would need changing to make sense, which feels like a breaking change to me. It would need to be something like 'set display on/off'. I think we should leave the MakeCode block as it is.
The microbit.speaker
object with off
and on
methods was added in cac1c0cf793e200f3a61ba5b33c7be52aea6c3ad
Audio, music and speech output are now changed to accept only a single pin (or None) as the argument to pin output selection. See 0c4287ca33702f85917bd706067a6ca41a21510f
We will not implement is_on() as there is little benefit and it's better to keep things lean and simple. I've update the docs in https://github.com/bbcmicrobit/micropython/pull/696.
The stop() functionality still to be covered in https://github.com/microbit-foundation/micropython-microbit-v2/issues/31 and how it interfaces with the pin modes and sound coming from other modules in issue https://github.com/microbit-foundation/micropython-microbit-v2/issues/50.
Right now on V2 these functions can take a tuple for the
pin
argument:This can be a bit confusing because:
pin=(pin0, pin1)
would not workpin=(pin0, pin1)
will throw an error, even though both pins are available theremusic.play(music.PYTHON, pin=(pin_0,))
will also throw an error in v1 and work on v2audio
andmusic
stop functions also take the pin argument, this should probably mirror the same format asplay
, which it currently doesn't doSince we can control sound output on the speaker via
pin_speaker.enable()
andpin_speaker.disable()
, we could revert thepin
argument to be the same as V1, and then document that music, speech and audio always route the sound to the built-in speaker as well and how that can be enabled/disabled.If the user only wanted sound via the speaker, and not any other pin, they can still do
audio.play(..., pin=pin_speaker)
.Alternatively,
microbit.pin_speaker.disable()
could becomemicrobit.speaker.disable()
, and to only use the speaker, the user could doaudio.play(..., pin=None)
. In this case we would be removing the idea of the speaker being a pin, and becomes something that plays sounds, and then the pin argument is the "additional place to route the sound output into".Thoughts?