Added tones and octopint
This commit is contained in:
45
src/tunes.h
Normal file
45
src/tunes.h
Normal file
@ -0,0 +1,45 @@
|
||||
#include "config.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
// Define melodies and their durations
|
||||
int melody1[] = { 440, 523, 659, 587 }; // Happy tune
|
||||
int noteDuration1[] = { 100, 50, 100, 150 };
|
||||
|
||||
int melody2[] = { 587, 659, 740, 659 }; // Tune 2
|
||||
int noteDuration2[] = { 150, 100, 150, 100 };
|
||||
|
||||
int melody3[] = { 440, 392 }; // Sad Tune
|
||||
int noteDuration3[] = { 200, 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
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user