audiopwmio¶
Audio output via digital PWM
The 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
call deinit() or use a context manager. See
Lifetime and ContextManagers for more info.
Since CircuitPython 5, Mixer, RawSample and WaveFile are moved
to audiocore.
-
class
audiopwmio.PWMAudioOut(left_channel: microcontroller.Pin, *, right_channel: microcontroller.Pin = None, quiescent_value: int = 32768)¶ Output an analog audio signal by varying the PWM duty cycle.
-
paused:Any¶ True when playback is paused. (read-only)
-
deinit(self)¶ Deinitialises the PWMAudioOut and releases any hardware resources for reuse.
-
__enter__(self)¶ No-op used by Context Managers.
-
__exit__(self)¶ Automatically deinitializes the hardware when exiting a context. See Lifetime and ContextManagers for more info.
-
play(self, sample: Any, *, loop: Any = False)¶ Plays the sample once when loop=False and continuously when loop=True. Does not block. Use
playingto block.Sample must be an
audiocore.WaveFile,audiocore.RawSample, oraudiomixer.Mixer.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.
-
stop(self)¶ Stops playback and resets to the start of the sample.
-