Build a jukebox with RTTTL ringtones
FunduinoPublished on
Klingeltöne im RTTTL-Format per Tastenpad auswählen und abspielen
You need this
Passive speaker - 8 Ohm, 85 dB, XH2.54 3-pin socket
3,40 € *Item no. F23108955About the product — Passive speaker - 8 Ohm, 85 dB, XH2.54 3-pin socket
Analog keyboard module - 5 buttons, 5 V
3,00 € *Item no. F23106483About the product — Analog keyboard module - 5 buttons, 5 V
LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V
6,21 € *Item no. F23107181About the product — LCD Module 20x4 - I2C, Blue Backlight, 3.3-5 V
All 3 parts together 12,61 € *Ready to ship immediately · Delivery time: 1-3 business days
* All prices include statutory VAT, plus shipping costs.
RTTTL ringtones
Required components
1 / 2
The circuit diagram
Install the required libraries
1 / 2
Include libraries and define variables
Include libraries and define variables
#include "PlayRtttl.hpp" #include "LiquidCrystal_I2C.h" // Set the LCD name (lcd) LiquidCrystal_I2C lcd(0x27, 20, 4); // Speaker pin #define Lautsprecher 7 // Variable for the pressed keypad button int GedrueckteTaste; String TitelSong; char TeDeum[] = "Charpentier/Te_Deum:d=4,o=5,b=63:8c,8f,16f,16g,8a,8f,c6,8a,8a,8a#,16c6,16a#,16a,16a#,8c6,16g,16f,16g,16a,8g,8c,8f,16f,16g,8a,8f,c6,8a,8a,16a#,16c6,16a,16a#,g,16f,2f"; char FuerElise[] = "Beethoven/Für_Elise:d=8,o=5,b=125:32p,e6,d#6,e6,d#6,e6,b,d6,c6,4a.,32p,c,e,a,4b.,32p,e,g#,b,4c.6,32p,e,e6,d#6,e6,d#6,e6,b,d6,c6,4a.,32p,c,e,a,4b.,32p,d,c6,b,2a"; char OdeandieFreude[] = "Beethoven/Ode_an_die_Freude:d=4,o=6,b=100:a5,a5,a_5,c,c,a_5,a5,g5,f5,f5,g5,a5,a.5,8g5,2g5,"; char Bolero[] = "Ravel/Bolero:d=4,o=5,b=80:c6,8c6,16b,16c6,16d6,16c6,16b,16a,8c6,16c6,16a,c6,8c6,16b,16c6,16a,16g,16e,16f,2g,16g,16f,16e,16d,16e,16f,16g,16a,g,g,";
The setup part
The setup part
void setup()
{
// Start the LCD
lcd.init();
// Turn on the LCD backlight
lcd.backlight();
}Query the keypad
Example: Querying the left button
// analogen Wert an A0 abfragen
int Analogwert = analogRead(A0);
switch (Analogwert)
{
case 0 ... 20:
// char-Array des Titels in String umwandeln
TitelSong = String(TeDeum);
// Funktion aufrufen, Interpret/Titel extrahieren
ZeigeTitel(TitelSong);
// Titel spielen
playRtttlBlocking(Lautsprecher, TeDeum);
break;
}The complete loop section
void loop()
{
// Check the keypad at input A0
int Analogwert = analogRead(A0);
switch (Analogwert)
{
// left button;
case 0 ... 20:
// Convert the title char array to a string
TitelSong = String(TeDeum);
// Call function to extract artist/title
ZeigeTitel();
// Play the title
playRtttlBlocking(Lautsprecher, TeDeum);
break;
// top button
case 30 ... 60:
TitelSong = String(FuerElise);
ZeigeTitel();
playRtttlBlocking(Lautsprecher, FuerElise);
break;
// right button
case 70 ... 120:
TitelSong = String(OdeandieFreude);
ZeigeTitel();
playRtttlBlocking(Lautsprecher, OdeandieFreude);
break;
// bottom button
case 150 ... 200:
TitelSong = String(Bolero);
ZeigeTitel();
playRtttlBlocking(Lautsprecher, Bolero);
break;
// outer right button -> display menu
case 300 ... 400:
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("1: Te Deum");
lcd.setCursor(0, 1);
lcd.print("2: F\365r Elise");
lcd.setCursor(0, 2);
lcd.print("3: Ode an die Freude");
lcd.setCursor(0, 3);
lcd.print("4: Bolero");
break;
}
}ShowTitle
ShowTitle
void ZeigeTitel()
{
// Teil des Strings bis zum ersten Doppelpunkt kürzen, enthält die Informationen zu Interpret und Titel
TitelSong = TitelSong.substring(0, TitelSong.indexOf(":"));
// _ durch leerzeichen ersetzen
TitelSong.replace("_", " ");
// erster Teil des Strings bis zum / -> Name des Interpreten
String Interpret = TitelSong.substring(0, TitelSong.indexOf("/"));
// zweiter Teil des Strings vom / + 1 bis zum Ende des Strings -> Name des Titels
String Titel = TitelSong.substring(TitelSong.indexOf("/") + 1, TitelSong.length());
// Titel auf dem LCD anzeigen
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Spiele:");
lcd.setCursor(0, 1);
lcd.print(Interpret);
lcd.setCursor(0, 2);
lcd.print(Titel);
}Rate the instructions