Connecting amp to a CLUE + using timer

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
hohx15
 
Posts: 1
Joined: Fri Dec 03, 2021 12:20 am

Connecting amp to a CLUE + using timer

Post by hohx15 »

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;
}

Locked
Please be positive and constructive with your questions and comments.

Return to “CLUE Board”