Arduboy2 Library  6.0.0
Arduboy2Audio.cpp
Go to the documentation of this file.
1 
7 #include "Arduboy2.h"
8 
9 bool Arduboy2Audio::audio_enabled = false;
10 
12 {
13  // fire up audio pins by seting them as outputs
14 #ifdef ARDUBOY_10
15  bitSet(SPEAKER_1_DDR, SPEAKER_1_BIT);
16  bitSet(SPEAKER_2_DDR, SPEAKER_2_BIT);
17 #else
18  bitSet(SPEAKER_1_DDR, SPEAKER_1_BIT);
19 #endif
20  audio_enabled = true;
21 }
22 
24 {
25  audio_enabled = false;
26  // shut off audio pins by setting them as inputs
27 #ifdef ARDUBOY_10
28  bitClear(SPEAKER_1_DDR, SPEAKER_1_BIT);
29  bitClear(SPEAKER_2_DDR, SPEAKER_2_BIT);
30 #else
31  bitClear(SPEAKER_1_DDR, SPEAKER_1_BIT);
32 #endif
33 }
34 
36 {
37  if (audio_enabled)
38  off();
39  else
40  on();
41 }
42 
44 {
45  EEPROM.update(Arduboy2Base::eepromAudioOnOff, audio_enabled);
46 }
47 
49 {
50  if (EEPROM.read(Arduboy2Base::eepromAudioOnOff))
51  on();
52  else
53  off();
54 }
55 
57 {
58  return audio_enabled;
59 }
Arduboy2Audio::off
static void off()
Turn sound off (mute).
Definition: Arduboy2Audio.cpp:23
Arduboy2Audio::on
static void on()
Turn sound on.
Definition: Arduboy2Audio.cpp:11
Arduboy2.h
The Arduboy2Base and Arduboy2 classes and support objects and definitions.
Arduboy2Audio::begin
static void begin()
Initialize the speaker based on the current mute setting.
Definition: Arduboy2Audio.cpp:48
Arduboy2Audio::saveOnOff
static void saveOnOff()
Save the current sound state in EEPROM.
Definition: Arduboy2Audio.cpp:43
Arduboy2Audio::toggle
static void toggle()
Toggle the sound on/off state.
Definition: Arduboy2Audio.cpp:35
Arduboy2Audio::enabled
static bool enabled()
Get the current sound state.
Definition: Arduboy2Audio.cpp:56