INHOUDSOPGAWE:
2025 Outeur: John Day | [email protected]. Laas verander: 2025-01-13 06:56
Esta es una rocola que cuenta with dos canciones, the theme of Harry Potter and la canción de Despacito van Luis Fonsi
Stap 1: materiaal
1 Protoboard
1 Arduino UNO
kabels trui macho-hembra y macho-macho
1 pantalla LCD 16x2
2 Buzzer pasivo
2 Drukknoppie
1 kabel USB vir Arduino
1 fuente de poder externa
Stap 2: Programmeer
Ons kan ook die biblioteca van die LCD en die program instel met 'n kombinasie van pinne. U kan ook veranderlikes installeer wat die kans kan bepaal, die twee weergawes kan verander, die veranderlike "anti-derrames" en die pin vir die buzzer.
#insluit
// librería para manejar pantallas LCD
LiquidCrystal lcd (12, 11, 5, 4, 3, 2); // Indica que pines se estan utilizando
int cantidad = 0;
const int botonI = 10; const int botonD = 9; int antramme = 0; // esta variable va a servir para evitar que el LCD muestre 3 cosas al mismo tiempo int buzzer_pin = 6;
Dit is 'n goeie idee om die funksies van die volgende te beskryf:
- Definieer elke ton van 'n kar (dit is 'n goeie idee om 'n sleutelbord te gebruik).
- Definir las notas (en letras), dándoles un valor único de Hz.
- Definit la la estructura de las notas (nota, semi-nota, ens).
Y por ultimo, definir el tempo en milisegundos
void setTone (int pin, int note, int duration) {tone (pin, note, duration); vertraging (duur); noTone (pen); } struct MusicStruct {int A = 550; int As = 582; int B = 617; int C = 654; int Cs = 693; int D = 734; int Ds = 777; int E = 824; int F = 873; int Fs = 925; int G = 980; int Gs = 1003; int A2 = 1100; int A2s = 1165; int B2 = 1234; int C3 = 1308; int C3s = 1385; int D3 = 1555; } Musiek; struct LengthStruct {float half = 0.5; dryf een = 1.0; dryf een_half = 1,5; vlot twee = 2.0; vlot twee_half = 2,5; } Lengte;
int tempo = 400; // velocidad de la composicion
Definitiewe todo eso, podemos empezar la parte interesante del programa.
Primero, hooi que:
- Monitor reeks
- Definieer los modusse van los pines van los botones en gonser
- Gee 'n LCD -skerm en 'n oorspronklike poslys
ongeldige opstelling () {Serial.begin (9600); pinMode (botonI, INPUT_PULLUP); pinMode (botonD, INPUT_PULLUP);
// Afkorting van pantalla LCD
lcd.begin (16, 2); // Enciende lcd lcd.clear (); lcd.setCursor (0, 0); // El proximo mensaje apracecera en la cordenada 0, 0 pinMode (buzzer_pin, OUTPUT);
}
Ons kan 'n paar funksies en funksies van die hoof (van die hoof van Harry Potter) gebruik.
Gebruik 2 vorme van toorkanale en este proyecto:
- Gebruik die funksie setTone, que definimos antes (Harry Potter)
- Die funksie van die buzzer van Arduino (Despacito)
Skrywer: 'n funksie vir 'n enkele solo -opname van 12 hoofstukke van die oorspronklike tydperk van 856 lyn
void jarri () {setTone (buzzer_pin, Music. B, tempo * Length.one); setTone (buzzer_pin, Music. E, tempo * Length.one_half); setTone (buzzer_pin, Music. G, tempo * Length.half); setTone (buzzer_pin, Music. F, tempo * Length.one); setTone (buzzer_pin, Music. E, tempo * Length.two); setTone (buzzer_pin, Music. B2, tempo * Length.one); setTone (buzzer_pin, Music. A2, tempo * Length.two_half); setTone (buzzer_pin, Music. Fs, tempo * Length.two_half); setTone (buzzer_pin, Music. E, tempo * Length.one_half); setTone (buzzer_pin, Music. G, tempo * Length.half); setTone (buzzer_pin, Music. F, tempo * Length.one); setTone (buzzer_pin, Music. Ds, tempo * Length.two); setTone (buzzer_pin, Music. F, tempo * Length.one); setTone (buzzer_pin, Music. B, tempo * Length.two_half);} void Despacito () {tone (buzzer_pin, 587, 709.720327982); vertraging (788.578142202); vertraging (10.3082110092); toon (buzzer_pin, 554, 709.720327982); vertraging (788.578142202); vertraging (5.15410550459); toon (buzzer_pin, 493, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 369, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 440, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 391, 412.843850917); vertraging (458.715389908); vertraging (5.15410550459); toon (buzzer_pin, 391, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 391, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 391, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 391, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 391, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 554, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 587, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 440, 412.843850917); vertraging (458.715389908); vertraging (5.15410550459); toon (buzzer_pin, 440, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 440, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 440, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 440, 41.7482545872); vertraging (46.3869495413); vertraging (36.0787385321); toon (buzzer_pin, 440, 37.109559633); vertraging (41.2328440367); vertraging (30.9246330275); toon (buzzer_pin, 440, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 587, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 587, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 587, 46.3869495413); vertraging (51.5410550459); vertraging (30.9246330275); toon (buzzer_pin, 587, 46.3869495413); vertraging (51.5410550459); vertraging (20.6164220183); toon (buzzer_pin, 587, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 659, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 659, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 554, 691.165548165); vertraging (767.961720183); vertraging (314.40043578); toon (buzzer_pin, 587, 552.004699541); vertraging (613.338555046); vertraging (5.15410550459); toon (buzzer_pin, 554, 552.004699541); vertraging (613.338555046); vertraging (5.15410550459); toon (buzzer_pin, 493, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 369, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 369, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 46.3869495413); vertraging (51.5410550459); vertraging (30.9246330275); toon (buzzer_pin, 493, 46.3869495413); vertraging (51.5410550459); vertraging (20.6164220183); toon (buzzer_pin, 493, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); toon (buzzer_pin, 440, 134.52215367); vertraging (149.469059633); vertraging (5.15410550459); toon (buzzer_pin, 493, 273.683002294); vertraging (304.092224771); vertraging (5.15410550459); }
Una vez tengamos todo esto, podemos pasar a la parte mas importante del programa del Arduino … el Loop ()
Eerste, definimos un label llamado leibel (espectacular nombre, lo sé), para que lleve al inicio del loop () cuando termine cada canción. Ons kan dit baie waardeer en veranderlike anti-derrames installeer, maar dit kan ook met LCD-skerms gekyk word, en dit is 'n onvergelykbare see.
U kan ook die waarde van hierdie funksie bepaal.
leemte -lus () {leibel: if ((antiderrames == 0) && (digitalRead (botonI) == 1) && (digitalRead (botonD) == 1)) {lcd.setCursor (0, 0); lcd.print ("Elegir cancion"); // CAMBIA el icono lcd.setCursor (0, 1); lcd.print ("1 o 2"); } anders {if (digitalRead (botonI) == 0) {delay (400); lcd.clear (); as (cantidad == 0) {cantidad = 1; } antyrame ++; } if (digitalRead (botonD) == 0) {delay (400); lcd.clear (); as (cantidad == 1) {cantidad = 0; } antiderrames ++; } as (cantidad == 0) {lcd.setCursor (0, 0); lcd.print ("Harry Potter"); // CAMBIA el icono lcd.setCursor (0, 1); lcd.print ("Tema"); jarri (); antirame = 0; lcd.clear (); goto leibel; // volvemos al inicio
}
anders as (cantidad == 1); {
lcd.setCursor (0, 0); lcd.print ("Despacito"); // CAMBIA el icono lcd.setCursor (0, 1); lcd.print ("Luis Fonsi"); Despacito (); antirame = 0; lcd.clear (); goto leibel; // volvemos al inicio}}}
Die program kan met funksies van die funksionele LCD 16x2 funksioneer, sowel as 'n program vir die finale program.
Stap 3: 4. Escoger Canciones Para Programarla
Sien buscaron 2 canciones para programarlas y así incluirlas para la rocola. En este caso serían las canciones of "Despacito" van Luis Fonsi en die tema van die Harry Potter -tema.
Stap 4: Ontlaai programme
Después de tener la programmeación de los botones, la pantalla en las canciones; Dit is 'n unieke probleem vir ons, en dit is ook moontlik om modifikasies en tinkercad te doen.
Stap 5: Convertirlo En Físico
Ons kan die funksie van die hardeware en die hardeware vir die resultate kopieer. Dit is 'n embargo, maar ons kan nie 'n ongerief vind nie, maar ons kan dit nie in kontak bring nie. Ons kan die finale solo -opname insluit, insluitend die botones en die buzzer.
Stap 6: Máquinas Utilizadas
Ons kan die Maker-Space-kaart gebruik om 'n karkas te gebruik.
Ons gebruik die cortadora de vinilo vir 'n hacer -plakker en 'n dekorasie vir die karkas
Maak gebruik van die voetstuk van die Maker-space vir hacer los agujeros vir die buzzer en die kabel van Arduino
Stap 7: Aanbevelings
Algunas recomendaciones si se piensa replicar este proyecto para mejores resultados es:
- Probar previamente el programa en la página de Tinkercad para ver cómo funciona. U kan ook die kabels en die konteks van die protobord en die arduino besoek.
- Al die inligting wat ek nodig het, is om 'n volledige kontak met ons te maak.
- Die volledige weergawe van die hardeware van die Tinkercad, wat die oorspronklike vorm vir 'n volledige weergawe van 'n porselein en 'n verifikasie kan verseker.
- Medir las dimensionses para la caja, así se podrá evitar que quede demasiado grande o muy pequeña.