Construye una jukebox con tonos de llamada RTTTL
FunduinoÚltima actualización el
Klingeltöne im RTTTL-Format per Tastenpad auswählen und abspielen
Eso necesitas
Altavoz pasivo - con conector hembra XH2.54 3P
3,40 € *N.º de art. F23108955Al producto — Altavoz pasivo - con conector hembra XH2.54 3P
Módulo de teclado analógico con cinco botones
3,00 € *N.º de art. F23106483Al producto — Módulo de teclado analógico con cinco botones
Módulo LCD 20x4 - I2C, iluminación azul, 3,3-5 V
6,21 € *N.º de art. F23107181Al producto — Módulo LCD 20x4 - I2C, iluminación azul, 3,3-5 V
Todas las 3 piezas en total 12,61 € *Listo para enviar de inmediato · Plazo de entrega: 1-3 días laborables
* Todos los precios incluyen el IVA legal, más gastos de envío.
Tonos de llamada RTTTL
Componentes necesarios
1 / 2
El esquema eléctrico
Instalar las bibliotecas necesarias
1 / 2
Incluir bibliotecas y definir variables
Incluir bibliotecas y definir variables
#include "PlayRtttl.hpp" #include "LiquidCrystal_I2C.h" // Definir el nombre de la pantalla LCD (lcd) LiquidCrystal_I2C lcd(0x27, 20, 4); // Pin del altavoz #define Altavoz 7 // Variable para la tecla pulsada del teclado int TeclaPulsada; String TituloCancion; 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 ParaElisa[] = "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 Oda_a_la_alegria[] = "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,";
La parte de configuración
La parte de configuración
void setup()
{
// Iniciar LCD
lcd.init();
// Encender la retroiluminación del LCD
lcd.backlight();
}Consultar el teclado matricial
Ejemplo: consulta del botón izquierdo
// 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;
}La sección completa del loop
void loop()
{
// Consultar el teclado de botones en la entrada A0
int Analogwert = analogRead(A0);
switch (Analogwert)
{
// botón izquierdo;
case 0 ... 20:
// Convertir el array de caracteres del título en una cadena
TitelSong = String(TeDeum);
// Llamar a la función para extraer el intérprete y el título
ZeigeTitel();
// Reproducir el título
playRtttlBlocking(Lautsprecher, TeDeum);
break;
// botón superior
case 30 ... 60:
TitelSong = String(FuerElise);
ZeigeTitel();
playRtttlBlocking(Lautsprecher, FuerElise);
break;
// botón derecho
case 70 ... 120:
TitelSong = String(OdeandieFreude);
ZeigeTitel();
playRtttlBlocking(Lautsprecher, OdeandieFreude);
break;
// botón inferior
case 150 ... 200:
TitelSong = String(Bolero);
ZeigeTitel();
playRtttlBlocking(Lautsprecher, Bolero);
break;
// botón exterior derecho -> mostrar menú
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;
}
}La función Mostrar título
La función Mostrar título
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);
}Calificar la guía