0% encontró este documento útil (0 votos)
119 vistas9 páginas

Arduino

Este documento contiene las notas musicales y ritmos de tres villancicos navideños ("Jingle Bells", "Santa Claus is Coming to Town" y "We Wish You a Merry Christmas") que pueden ser reproducidos mediante tres pulsadores. Al presionar cada pulsador, se reproduce la melodía correspondiente a través de un zumbador, mientras las luces LED cambian de color aleatoriamente.
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
119 vistas9 páginas

Arduino

Este documento contiene las notas musicales y ritmos de tres villancicos navideños ("Jingle Bells", "Santa Claus is Coming to Town" y "We Wish You a Merry Christmas") que pueden ser reproducidos mediante tres pulsadores. Al presionar cada pulsador, se reproduce la melodía correspondiente a través de un zumbador, mientras las luces LED cambian de color aleatoriamente.
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como DOCX, PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 9

// Notas de la tonada Jingle Bells

int melody[] = {

NOTE_E5, NOTE_E5, NOTE_E5,

NOTE_E5, NOTE_E5, NOTE_E5,

NOTE_E5, NOTE_G5, NOTE_C5, NOTE_D5,

NOTE_E5,

NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,

NOTE_F5, NOTE_E5, NOTE_E5, NOTE_E5, NOTE_E5,

NOTE_E5, NOTE_D5, NOTE_D5, NOTE_E5,

NOTE_D5, NOTE_G5

};

int tempo[] = {

8, 8, 4,

8, 8, 4,

8, 8, 8, 8,

2,

8, 8, 8, 8,

8, 8, 8, 16, 16,

8, 8, 8, 8,

4, 4

};

// Fin Notas de la tonada Jingle Bells

// Notas de la tonada We wish you a merry Christmas

int wish_melody[] = {
NOTE_B3,

NOTE_F4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4,

NOTE_D4, NOTE_D4, NOTE_D4,

NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_F4,

NOTE_E4, NOTE_E4, NOTE_E4,

NOTE_A4, NOTE_A4, NOTE_B4, NOTE_A4, NOTE_G4,

NOTE_F4, NOTE_D4, NOTE_B3, NOTE_B3,

NOTE_D4, NOTE_G4, NOTE_E4,

NOTE_F4

};

int wish_tempo[] = {

4,

4, 8, 8, 8, 8,

4, 4, 4,

4, 8, 8, 8, 8,

4, 4, 4,

4, 8, 8, 8, 8,

4, 4, 8, 8,

4, 4, 4,

};

// Fin de Notas de la tonada We wish you a merry Christmas

// Notas de la tonada Santa Claus is coming to town

int santa_melody[] = {

NOTE_G4,
NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_G4,

NOTE_A4, NOTE_B4, NOTE_C5, NOTE_C5, NOTE_C5,

NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_G4,

NOTE_A4, NOTE_G4, NOTE_F4, NOTE_F4,

NOTE_E4, NOTE_G4, NOTE_C4, NOTE_E4,

NOTE_D4, NOTE_F4, NOTE_B3,

NOTE_C4

};

int santa_tempo[] = {

8,

8, 8, 4, 4, 4,

8, 8, 4, 4, 4,

8, 8, 4, 4, 4,

8, 8, 4, 2,

4, 4, 4, 4,

4, 2, 4,

};

// Fin de Notas de la tonada Santa Claus is coming to town

// Activamos o inicializamos los pines de entrada de los pulsadores

int switchOne = 0; // Pulsador para Reproducir "Jingle Bells"

int switchTwo = 0; // Pulsador para Reproducir "Santa Claus Is Coming To Town"

int switchThree = 0; // Pulsador para Reproducir "We Wish You a Merry Christmas"

void setup() { // Activamos los pines de entrada y salida de los LEDs


pinMode(red, OUTPUT); // salida de color rojo

pinMode(green, OUTPUT); // salida de color verde

pinMode(blue, OUTPUT); // salida de color azul

pinMode(9, OUTPUT); // Respuesta del Buzzer pasivo o Zumbador que da el sonido y al tiempo
enciende el LED RGB multicolor en cada tonada

pinMode(13, OUTPUT); // Led que indica cuando suene un villancico

pinMode(2, INPUT); // Reproducir "Jingle Bells" al presionar el botón 1

pinMode(3, INPUT); // Reproducir "Santa Claus Is Coming To Town" al presionar el botón 2

pinMode(4, INPUT); // Reproducir "We Wish You a Merry Christmas" al presionar el botón 3

void loop() { // Bucle de acciones al presionar cada botón

switchOne = digitalRead(2); // Pulsador 1 se activa en el pin 2

switchTwo = digitalRead(3); // Pulsador 2 se activa en el pin 3

switchThree = digitalRead(4); // Pulsador 3 se activa en el pin 4

if (switchOne == HIGH) { // si presionó Pulsador 1

sing(1); // Reproducir "Jingle Bells"

else if (switchTwo == HIGH) { // si presionó Pulsador 2

sing(2); // Reproducir "Santa Claus Is Coming To Town"

else if (switchThree == HIGH) { // si presionó Pulsador 3

sing(3); // Reproducir "We Wish You a Merry Christmas"

}
// Código de las canciones o villancicos

int song = 0;

void sing (int s) {

// iterate over the notes of the melody:

song = s;

if (song == 3) {

Serial.println(" 'We wish you a Merry Christmas'");

int size = sizeof(wish_melody) / sizeof(int);

for (int thisNote = 0; thisNote < size; thisNote++) {

// to calculate the note duration, take one second

// divided by the note type.

//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.

int noteDuration = 1000 / wish_tempo[thisNote];

buzz(melodyPin, wish_melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.

// the note's duration + 30% seems to work well:

int pauseBetweenNotes = noteDuration * 1.30;

delay(pauseBetweenNotes);

// stop the tone playing:

buzz(melodyPin, 0, noteDuration);
}

} else if (song == 2) {

Serial.println(" 'Santa Claus is coming to town'");

int size = sizeof(santa_melody) / sizeof(int);

for (int thisNote = 0; thisNote < size; thisNote++) {

// to calculate the note duration, take one second

// divided by the note type.

//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.

int noteDuration = 900 / santa_tempo[thisNote];

buzz(melodyPin, santa_melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.

// the note's duration + 30% seems to work well:

int pauseBetweenNotes = noteDuration * 1.30;

delay(pauseBetweenNotes);

// stop the tone playing:

buzz(melodyPin, 0, noteDuration);

else {

Serial.println(" 'Jingle Bells'");

int size = sizeof(melody) / sizeof(int);

for (int thisNote = 0; thisNote < size; thisNote++) {


// to calculate the note duration, take one second

// divided by the note type.

//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.

int noteDuration = 1000 / tempo[thisNote];

buzz(melodyPin, melody[thisNote], noteDuration);

// to distinguish the notes, set a minimum time between them.

// the note's duration + 30% seems to work well:

int pauseBetweenNotes = noteDuration * 1.30;

delay(pauseBetweenNotes);

// stop the tone playing:

buzz(melodyPin, 0, noteDuration);

// Fin Código de las canciones o villancicos

// Código que activa las luces LED cada que se reproduce un villancico

void buzz(int targetPin, long frequency, long length) {

//inicializamos las variables para los colores de los leds

int redValue = 0;

int greenValue = 0;

int blueValue=0;
digitalWrite(13, HIGH); // se enciende el LED del pin 13 cuando suenan las canciones o villancicos

//Los colores son generados aleatoriamente con esta instrucción random

redValue=random(0,255);

greenValue=random(0,255);

blueValue=random(0,255);

// Se envía el valor de los colores básicos para generar cada color final

analogWrite(red, redValue);

analogWrite(green, greenValue);

analogWrite(blue, blueValue);

long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions

//// 1 second's worth of microseconds, divided by the frequency, then split in half since

//// there are two phases to each cycle

long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing

//// multiply frequency, which is really cycles per second, by the number of seconds to

//// get the total number of cycles to produce

for (long i = 0; i < numCycles; i++) { // for the calculated length of time...

digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram

delayMicroseconds(delayValue); // wait for the calculated delay value

digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram

delayMicroseconds(delayValue); // wait again or the calculated delay value

digitalWrite(13, LOW); // pin 13 apagado si no se reproduce ninguna canción

digitalWrite(12, LOW); // pin 12 rojo apagado si no se reproduce ninguna canción y al finalizar


cada villancico
digitalWrite(11, LOW); // pin 11 verde apagado si no se reproduce ninguna canción y al finalizar
cada villancico

digitalWrite(10, LOW); // pin 10 azul apagado si no se reproduce ninguna canción y al finalizar


cada villancico

También podría gustarte