52 lines
1.5 KiB
C
52 lines
1.5 KiB
C
#include "config.h"
|
|
#include <Arduino.h>
|
|
|
|
// Define melodies and their durations
|
|
int melody1[] = { 440, 523, 659, 587 }; // Startup tune
|
|
int noteDuration1[] = { 100, 50, 100, 150 };
|
|
|
|
int melody2[] = { 740, 784, 659 }; // Happy Tune
|
|
int noteDuration2[] = { 120, 120, 120 };
|
|
|
|
int melody3[] = { 440, 349, 392 }; // Sad Tune
|
|
int noteDuration3[] = { 150, 100, 150 };
|
|
|
|
|
|
// Function to play a specified tune
|
|
void playTune(int tuneIndex) {
|
|
int* melody = nullptr; // Use pointer instead of array
|
|
int* noteDuration = nullptr; // Use pointer instead of array
|
|
int melodySize = 0; // To store the size of the melody
|
|
|
|
switch(tuneIndex) {
|
|
case 1:
|
|
melody = melody1;
|
|
noteDuration = noteDuration1;
|
|
melodySize = sizeof(melody1) / sizeof(melody1[0]);
|
|
break;
|
|
case 2:
|
|
melody = melody2;
|
|
noteDuration = noteDuration2;
|
|
melodySize = sizeof(melody2) / sizeof(melody2[0]);
|
|
break;
|
|
case 3:
|
|
melody = melody3;
|
|
noteDuration = noteDuration3;
|
|
melodySize = sizeof(melody3) / sizeof(melody3[0]);
|
|
break;
|
|
default:
|
|
return; // Invalid tune index
|
|
}
|
|
|
|
for (int i = 0; i < melodySize; i++) {
|
|
tone(PIN_BUZZER, melody[i], noteDuration[i]);
|
|
delay(noteDuration[i] + 20);
|
|
noTone(PIN_BUZZER); // Stop the tone
|
|
}
|
|
}
|
|
|
|
void beep(int buzz) {
|
|
tone(PIN_BUZZER, buzz, 100);
|
|
delay(100);
|
|
noTone(PIN_BUZZER);
|
|
} |