Arduino
Arduino
int melody[] = {
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
};
int wish_melody[] = {
NOTE_B3,
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,
};
int santa_melody[] = {
NOTE_G4,
NOTE_E4, NOTE_F4, NOTE_G4, NOTE_G4, NOTE_G4,
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,
};
int switchThree = 0; // Pulsador para Reproducir "We Wish You a Merry Christmas"
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(4, INPUT); // Reproducir "We Wish You a Merry Christmas" al presionar el botón 3
}
// Código de las canciones o villancicos
int song = 0;
song = s;
if (song == 3) {
delay(pauseBetweenNotes);
buzz(melodyPin, 0, noteDuration);
}
} else if (song == 2) {
delay(pauseBetweenNotes);
buzz(melodyPin, 0, noteDuration);
else {
delay(pauseBetweenNotes);
buzz(melodyPin, 0, noteDuration);
// Código que activa las luces LED cada que se reproduce un villancico
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
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
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
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
digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram