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

microphone.is_event() question #36

Closed microbit-carlos closed 3 years ago

microbit-carlos commented 3 years ago

Just to make sure this is correct:

dpgeorge commented 3 years ago

There are two kinds of histories:

was_event(event) will return true if that event is in S, and remove that event from S. It will also clear L.

is_event(event) returns true if that event is the most recent (last) event in L.

get_events() returns a copy of L and clears L.

Not sure if that's all sensible, but that's how v1 worked :)

martinwork commented 3 years ago

I was thinking was_event and is_event would behave like button was_pressed and is_pressed.

How does current_event relate to S and L?

Would it be helpful to have was_loud, was_quiet, is_loud and is_quiet, that do behave like the button functions?

martinwork commented 3 years ago

I don't know what L is used for. Could it be a circular buffer that records the most recent events, and doesn't get stuck?

dpgeorge commented 3 years ago

The semantics of microphone.is_event() have been improved in c57910ce1d6957dda43d5a8e4596d511be20b446 so it doesn't get blocked by the history filling up.

Test code:

while True:
    print(microphone.is_event(SoundEvent.LOUD), microphone.is_event(SoundEvent.QUIET))

That should swap between False True and True False when noise is made.

jaustin commented 3 years ago

Thanks Damien, that sounds perfect.