Due to high demand expect some shipping delays at this time, orders may not ship for 3-4 business days. On MLK Day no orders will be shipped.
0

Connecting amp to a CLUE + using timer
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Connecting amp to a CLUE + using timer

by hohx15 on Fri Dec 03, 2021 12:29 am

Hello experts,

I am trying to build a timer with speaker based on CLUE.
My questions are :

(1) (BOARD CONFIGURATION)
How do I connect Adafruit Mono 2.5W Class D Audio Amplifier - PAM8302 on the breadboard?
Just one output pin - amp - GND like horizontally on each end of the amp?

(2) (CODE)
What do I need to do in Arduino IDE ?
What kind of code or header files do I need to control the speaker?

(3) (PIN)
I have already soldered pin 2 as output. Does it matter which pin I use?

(4) TIMER
Here is my code for my timer, and why does it not play music on D46 built in speaker after time is up?


volatile uint16_t milliseconds = 8000;


void timercallback() {
timecounter = milliseconds/1000;

//analogWrite(LED_BUILTIN, milliseconds); // pulse the LED
if (milliseconds == 0) {

delay(1000);
playMusic();
milliseconds = 8000;

} else {
milliseconds--;

}
}
void setup() {

pinMode(46, OUTPUT);
Serial.begin(115200);
}

void loop{
timercallback();
}

int speed=50; //higher value, slower notes

bool playMusic(){

for (int thisNote = 0; melody[thisNote]!=-1; thisNote++) {

int noteDuration = speed*noteDurations[thisNote];
tone(46, melody[thisNote],noteDuration*.95);
Serial.println(melody[thisNote]);
delay(noteDuration);
noTone(46);

}

return true;
}

hohx15
 
Posts: 1
Joined: Fri Dec 03, 2021 12:20 am

Please be positive and constructive with your questions and comments.


cron