Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Here is an example code for the Adafruit 2.8W Stereo Class D Audio Amplifier with I2C Control AGC:
- This code initializes the Adafruit 2.8W Stereo Class D Audio Amplifier with I2C Control AGC and sets it to use Automatic Gain Control (AGC) mode. The begin() function is used to initialize the audio amplifier, and the setAGC(), setGain(), and setVolume() functions are used to set the AGC mode, gain, and volume, respectively.
- To use this code, connect the Adafruit 2.8W Stereo Class D Audio Amplifier with I2C Control AGC to the I2C pins of your Arduino board (usually A4 and A5 for most Arduino boards). The audio amplifier should be powered with a 3.7-5V DC power source.
- Note that this code only initializes the audio amplifier and sets it to use AGC mode with maximum gain and volume. You will need to add additional code to play audio through the audio amplifier, such as reading audio data from a file or a microphone, and sending it to the audio amplifier.
- */
- #include <Wire.h>
- #include <Adafruit_TPA2016.h>
- Adafruit_TPA2016 audio_amp = Adafruit_TPA2016();
- void setup() {
- Serial.begin(9600);
- Wire.begin();
- if (!audio_amp.begin(Wire)) {
- Serial.println("Failed to find TPA2016 chip");
- while (1);
- }
- // Set AGC mode
- audio_amp.setAGC(true);
- // Set gain to maximum (24 dB)
- audio_amp.setGain(0x1F);
- // Set volume to maximum (0 dB)
- audio_amp.setVolume(0x00);
- Serial.println("Audio amplifier initialized");
- }
- void loop() {
- // Do nothing
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement