async_buzzer

Play simple tunes on a piezo buzzer asynchronously

  • Author(s): Phil Underwood

Implementation Notes

Hardware:

  • This works with passive piezo transducers.

Software and Dependencies:

class async_buzzer.Buzzer(pwm: pwmio.PWMOut)

Async implementation of a buzzer that can play simple tunes

Parameters:

pwm (PWMOut) – pwm to use for output

play(notes: Sequence[Tuple[str | float, float]])

Start playing a series of notes. They will play using asyncio in the background.

Parameters:

notes (list) – A sequence of tuples of frequency and duration (in ms). Frequency can also be specified as a note string e.g “C#6”. Note for reasons of space only notes between C2 and C8 can be referenced by name, but any numeric frequency can be used. What frequencies actually work will depend on your transducer.

Returns:

None

stop()

Stop playing

async wait()

Wait for the current tune to finish. This may finish early if a new tune is played

class async_buzzer.Note(freq, duration)

Create new instance of Note(freq, duration)

duration

Alias for field number 1

freq

Alias for field number 0