Audio output via digital PWM
audiopwmio module contains classes to provide access to audio IO.
All classes change hardware state and should be deinitialized when they
are no longer needed if the program continues after use. To do so, either
deinit() or use a context manager. See
Lifetime and ContextManagers for more info.
PWMAudioOut(left_channel: microcontroller.Pin, *, right_channel: Optional[microcontroller.Pin] = None, quiescent_value: int = 32768)¶
Output an analog audio signal by varying the PWM duty cycle.
True when playback is paused. (read-only)
Deinitialises the PWMAudioOut and releases any hardware resources for reuse.
No-op used by Context Managers.
Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
play(self, sample: audiocore._AudioSample, *, loop: bool = False)¶
Plays the sample once when loop=False and continuously when loop=True. Does not block. Use
The sample itself should consist of 16 bit samples. Microcontrollers with a lower output resolution will use the highest order bits to output. For example, the SAMD21 has a 10 bit DAC that ignores the lowest 6 bits when playing 16 bit samples.
Stops playback and resets to the start of the sample.
Stops playback temporarily while remembering the position. Use
resumeto resume playback.