microbit-foundation / micropython-microbit-v2

Temporary home for MicroPython for micro:bit v2 as we stablise it before pushing upstream
MIT License
43 stars 24 forks source link

Create SoundEvent class #20

Closed microbit-carlos closed 3 years ago

microbit-carlos commented 3 years ago

To capture the current 'loud' and 'quiet' options and give us the possibility to expand it in the future to other types of events.

Something along these lines:

class MicroBitSoundEvent:
    LOUD = None
    QUIET = None

    def __init__(self, event_name: string) -> None:
        self.event_name = event_name

    def __str__(self) -> string:
        return "SoundEvent('{}')".format(self.event_name)

    def __repr__(self) -> string:
        return self.__str__()

MicroBitSoundEvent.LOUD = MicroBitSoundEvent("loud")
MicroBitSoundEvent.QUIET = MicroBitSoundEvent("quiet")
SoundEvent = MicroBitSoundEvent

So that the user code will end up:

microphone.was_event(SoundEvent.LOUD)
jaustin commented 3 years ago

@microbit-giles is currently drafting resources against this speculative API so important that the first public relese uses this.

dpgeorge commented 3 years ago

Done in 18eb9de1e88afca0fb2615a2bc483d0e3a214fd3