#include <LiquidCrystal.h>
#include <driver/ledc.h>
LiquidCrystal lcd(22, 23, 5, 18, 19, 21);
const int BUZZER_PIN = 14; // Pin conectado al zumbador o altavoz
const int ledChannel = 0; // Canal LEDC para tu aplicación
const int resolution = 6; // Resolución (bits) para LEDC
// Frecuencias de las notas de la canción "Piches" de Mario Bros
const int NOTE_C4 = 262;
const int NOTE_E4 = 330;
const int NOTE_F4 = 349;
const int NOTE_G4 = 392;
const int NOTE_A4 = 440;
const int NOTE_D4 = 440;
void setup() {
lcd.begin(16, 2);
pinMode(BUZZER_PIN, OUTPUT);
// Configuración del canal LEDC
ledcSetup(ledChannel, 5000, resolution); // Frecuencia: 5000 Hz, Resolución: 6 bits
ledcAttachPin(BUZZER_PIN, ledChannel);
}
void loop() {
// Muestra el texto fijo en la primera fila con notas musicales
lcd.clear();
lcd.setCursor(0, 0);
playMelodyWithText("PICHES");
delay(8000);
// Mueve el texto de derecha a izquierda en la segunda fila
for (int i = 0; i < 16; i++) {
lcd.clear();
lcd.setCursor(i, 1);
playMelody();
delay(500);
}
// Mueve el texto de izquierda a derecha en la segunda fila
for (int i = 15; i >= 0; i--) {
lcd.clear();
lcd.setCursor(i, 1);
playMelody();
delay(500);
}
}
void playTone(int frequency, int duration) {
tone(BUZZER_PIN, frequency, duration);
delay(duration);
noTone(BUZZER_PIN);
}
void playMelody() {
// Melodía del tema "Piches" de Mario Bros
int melody[] = {
NOTE_E4, NOTE_E4, 0, NOTE_E4,
0, NOTE_C4, NOTE_E4, 0,
NOTE_G4, 0, 0, 0,
NOTE_G4, 0, 0, 0,
NOTE_C4, 0, 0, NOTE_G4,
0, 0, NOTE_E4, 0,
0, NOTE_A4, 0, NOTE_A4,
0, NOTE_A4, NOTE_G4, 0,
NOTE_E4, NOTE_E4, 0,
NOTE_G4, NOTE_G4, NOTE_F4,
NOTE_E4, 0, NOTE_C4,
NOTE_D4, NOTE_C4, 0,
NOTE_G4, NOTE_G4, NOTE_F4,
NOTE_E4, 0, NOTE_C4,
NOTE_D4, NOTE_C4, 0,
NOTE_A4, NOTE_A4, NOTE_A4
};
// Duraciones de cada nota (en milisegundos)
int noteDurations[] = {
150, 150, 300, 150,
300, 150, 150, 300,
150, 300, 150, 150,
150, 150, 150, 150,
150, 150, 150, 150,
300, 150, 150, 300,
300, 150, 300, 150,
300, 150, 150, 300,
150, 150, 300,
150, 150, 200,
150, 150, 300,
150, 150, 300,
150, 150, 200,
150, 150, 300,
150, 150, 300,
150, 150, 200
};
// Reproduce cada nota de la melodía
for (int i = 0; i < 52; i++) {
int noteDuration = 1000 / noteDurations[i];
playTone(melody[i], noteDuration);
int pauseBetweenNotes = noteDuration * 1.0; // Pausa entre notas
delay(pauseBetweenNotes);
}
}
void playMelodyWithText(const char* text) {
int textLength = strlen(text);
for (int i = 0; i < textLength; i++) {
lcd.print(text[i]);
delay(300); // Ajusta la velocidad del desplaz
}
}