Arduboy2 Library
6.0.0
|
Provide speaker and sound control. More...
#include <Arduboy2Audio.h>
Static Public Member Functions | |
static void | begin () |
Initialize the speaker based on the current mute setting. More... | |
static void | on () |
Turn sound on. More... | |
static void | off () |
Turn sound off (mute). More... | |
static void | toggle () |
Toggle the sound on/off state. More... | |
static void | saveOnOff () |
Save the current sound state in EEPROM. More... | |
static bool | enabled () |
Get the current sound state. More... | |
Provide speaker and sound control.
This class provides functions to initialize the speaker and control the enabling and disabling (muting) of sound. It doesn't provide any functions to actually produce sound.
The state of sound muting is stored in system EEPROM and so is retained over power cycles.
An Arduboy2Audio class object named audio
will be created by the Arduboy2Base class, so there is no need for a sketch itself to create an Arduboy2Audio object. Arduboy2Audio functions can be called using the Arduboy2 or Arduboy2Base audio
object.
Example:
In order for this class to be fully functional, the external library or functions used by a sketch to actually to produce sounds should be compliant with this class. This means they should only produce sound if it is enabled, or mute the sound if it's disabled. The enabled()
function can be used to determine if sound is enabled or muted. Generally a compliant library would accept the enabled()
function as an initialization parameter and then call it as necessary to determine the current state.
For example, the ArduboyTones and ArduboyPlaytune libraries require an enabled()
type function to be passed as a parameter in the constructor, like so:
Definition at line 73 of file Arduboy2Audio.h.
|
static |
Initialize the speaker based on the current mute setting.
The speaker is initialized based on the current mute setting saved in system EEPROM.
Definition at line 48 of file Arduboy2Audio.cpp.
|
static |
Get the current sound state.
true
if sound is currently enabled (not muted).This function should be used by code that actually generates sound. If true
is returned, sound can be produced. If false
is returned, sound should be muted.
Definition at line 56 of file Arduboy2Audio.cpp.
|
static |
Turn sound off (mute).
The system is configured to not produce sound (mute). This function sets the sound mode only until the unit is powered off. To save the current mode use saveOnOff()
.
Definition at line 23 of file Arduboy2Audio.cpp.
|
static |
Turn sound on.
The system is configured to generate sound. This function sets the sound mode only until the unit is powered off. To save the current mode use saveOnOff()
.
Definition at line 11 of file Arduboy2Audio.cpp.
|
static |
Save the current sound state in EEPROM.
The current sound state, set by on()
or off()
, is saved to the reserved system area in EEPROM. This allows the state to carry over between power cycles and after uploading a different sketch.
Definition at line 43 of file Arduboy2Audio.cpp.
|
static |
Toggle the sound on/off state.
If the system is configured for sound on, it will be changed to sound off (mute). If sound is off, it will be changed to on. This function sets the sound mode only until the unit is powered off. To save the current mode use saveOnOff()
.
Definition at line 35 of file Arduboy2Audio.cpp.