Does RTTTL work with tone()? - Electron

As part of my Kiosk project I wanted to add sound feedback when a child scans their tag. I found tone() in the documentation and I’ve made the example usage work inline with scanning the RFID tags.

Then I found this awesome post on making a Remote RTTTL song player, but I’m confused since it says it doesn’t use tone(), then later on in the discussion @BDub and @zenvisuals discuss incorporating the library because tone() is now in the firmware? Not sure if these means you can do RTTTL with tone() now, or not?

If it doesn’t that’s cool, but how would or where can I find a way replicate the RickRoll :smile: RTTTL song using tone()? And if it does, well I’m still confused.

Thank you!

RickRoll from the RTTTL post

//char *song = (char *)"RickRoll:d=4,o=5,b=200:8g,8a,8c6,8a,e6,8p,e6,8p,d6.,p,8p,8g,8a,8c6,8a,d6,8p,d6,8p,c6,8b,a.,8g,8a,8c6,8a,2c6,d6,b,a,g.,8p,g,2d6,2c6.,p,8g,8a,8c6,8a,e6,8p,e6,8p,d6.,p,8p,8g,8a,8c6,8a,2g6,b,c6.,8b,a,8g,8a,8c6,8a,2c6,d6,b,a,g.,8p,g,2d6,2c6.";

tone() example from documentation

//char *song = (char *)"2.34kHzBeeps:d=4,o=7,b=240:d,p,d,p,d,p,d,p";
int melody[] = {1908,2551,2551,2273,2551,0,2024,1908}; //C4,G3,G3,A3,G3,0,B3,C4

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {4,8,8,4,4,4,4,4};

This version definitely uses tone, despite the numerous comments to the contrary. The code looks pretty easy to add to any project, though I didn’t try it. Just add RTTTL.cpp and .h from the library directory.

You could also look into something like this
A great & very cheap MP3 sound module without need for a library!

Or you could also look into the DAC capabilities for some less 80s sounds :wink:

2 Likes

Oh, I didn’t see this zenvisuals/Remote-RTTTL/blob/master/library/example.ino. Totally easy!

Thank you!

I saw that! Since I already had the parts, tone() seemed like a no-brainer.

My ultimate goal is to actually have monkey (think Curious George) or other animal sounds for alerts. Are you saying this DAC you speak of might offer this ability?

The DAC pin(s) can output “real” analog signals (even stereo), so playing back 12bit PCM audio is possible with not much effort either.
But if you only want to play predefined sound clips I’d definetly spend $3 for such a MP3 module, and it comes with a little audio amp too :wink:

3 Likes