Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

How Do I Play Tones on the Adafruit Magtag in Arduino?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

How Do I Play Tones on the Adafruit Magtag in Arduino?

by harbertc on Mon Apr 12, 2021 9:10 pm

The guide here, https://learn.adafruit.com/adafruit-mag ... ino-basics, says you can enable the speaker to "play tones or short audio clips" but there are no examples. I assumed "tone(A0, 440)" would work here, but the method is not declared. How do you get the Magtag to play tones in Arduino?

harbertc
 
Posts: 3
Joined: Thu Jul 25, 2019 3:37 pm

Re: How Do I Play Tones on the Adafruit Magtag in Arduino?

by mikeysklar on Wed Apr 14, 2021 5:16 pm

Yeah tone() is not built into ESP32 Arduino Core.

You can use the ESP32Servo Library which has both analogWrite and tone builtin. It is available through the Arduino IDE library manager.

https://github.com/madhephaestus/ESP32Servo

Make sure you enable the speaker first.

Code: Select all | TOGGLE FULL SIZE
// set speaker enable pin to output
  pinMode(SPEAKER_SHUTDOWN, OUTPUT);
  // and immediately disable it to save power
  digitalWrite(SPEAKER_SHUTDOWN, LOW);

mikeysklar
 
Posts: 4229
Joined: Mon Aug 01, 2016 8:10 pm

Re: How Do I Play Tones on the Adafruit Magtag in Arduino?

by adafruit2 on Thu Apr 15, 2021 1:33 pm

try using this funciton

Code: Select all | TOGGLE FULL SIZE
void tone(uint8_t pin, float frequecy, float duration) {
  ledcSetup(1, frequecy * 80, 8);
  ledcAttachPin(pin, 1);
  ledcWrite(1, 128);
  delay(duration);
  ledcWrite(1, 0);
}

adafruit2
Site Admin
 
Posts: 19978
Joined: Fri Mar 11, 2005 7:36 pm

Please be positive and constructive with your questions and comments.