Baby Monitoring System
Loading...
Searching...
No Matches
Songs.h
Go to the documentation of this file.
1
8#ifndef SONGS_H
9#define SONGS_H
10
11#include <Arduino.h>
12
16int song1Notes[] = {
17 261, 261, 392, 392, 440, 440, 392, // C C G G A A G
18 349, 349, 329, 329, 294, 294, 261, // F F E E D D C
19 392, 392, 349, 349, 329, 329, 294, // G G F F E E D
20 392, 392, 349, 349, 329, 329, 294, // G G F F E E D
21 261, 261, 392, 392, 440, 440, 392, // C C G G A A G
22 349, 349, 329, 329, 294, 294, 261 // F F E E D D C
23};
28 4, 4, 4, 4, 4, 4, 2,
29 4, 4, 4, 4, 4, 4, 2,
30 4, 4, 4, 4, 4, 4, 2,
31 4, 4, 4, 4, 4, 4, 2,
32 4, 4, 4, 4, 4, 4, 2,
33 4, 4, 4, 4, 4, 4, 2
34};
35
39int song2Notes[] = {
40 330, 294, 262, 294, 330, 330, 330, // E D C D E E E
41 294, 294, 294, 330, 392, 392, // D D D E G G
42 330, 294, 262, 294, 330, 330, 330, // E D C D E E E
43 330, 294, 294, 330, 294, 262 // E D D E D C
44};
49 4, 4, 4, 4, 4, 4, 2,
50 4, 4, 2, 4, 4, 2,
51 4, 4, 4, 4, 4, 4, 4,
52 4, 4, 4, 4, 4, 1
53};
54
58int song3Notes[] = {
59 262, 349, 349, 349, 349, 440, 262, 440, 349, 0, // C F F F F A C A F
60 392, 392, 392, 330, 294, 262, // G G G E D C
61 262, 349, 349, 349, 349, 440, 262, 440, 349, 0, // C F F F F A C A F
62 392, 262, 349 // G C F
63};
68 4, 4, 8, 8, 4, 4, 4, 4, 4, 4,
69 4, 4, 2, 4, 4, 4,
70 4, 4, 8, 8, 4, 4, 4, 4, 2, 4,
71 2, 2, 1
72};
73
82void playNotes(int buzzerPin, int notes[], int durations[], int length) {
83 // cycle through each note of the songs note array
84 for (int thisNote = 0; thisNote < length; thisNote++) {
85 int noteDuration = 1000 / durations[thisNote];
86 tone(buzzerPin, notes[thisNote]);
87 vTaskDelay(noteDuration / portTICK_PERIOD_MS);
88 noTone(buzzerPin);
89 vTaskDelay(200 / portTICK_PERIOD_MS);
90 }
91}
92
99void playSong(int buzzerPin, int songNum) {
100 switch (songNum) {
101 case 1:
102 playNotes(buzzerPin, song1Notes, song1NoteDurations, sizeof(song1Notes) / sizeof(int));
103 break;
104 case 2:
105 playNotes(buzzerPin, song2Notes, song2NoteDurations, sizeof(song2Notes) / sizeof(int));
106 break;
107 case 3:
108 playNotes(buzzerPin, song3Notes, song3NoteDurations, sizeof(song3Notes) / sizeof(int));
109 break;
110 default:
111 Serial.println("Invalid selection. Please enter 1, 2, or 3.");
112 break;
113 }
114}
115
116#endif
int song1NoteDurations[]
Durations for notes in "Twinkle Twinkle Little Star".
Definition Songs.h:27
void playNotes(int buzzerPin, int notes[], int durations[], int length)
Plays each note for a given song.
Definition Songs.h:82
int song3Notes[]
Frequency values for notes in "The Wheels on the Bus".
Definition Songs.h:58
int song2Notes[]
Frequency values for notes in "Mary Had a Little Lamb".
Definition Songs.h:39
int song3NoteDurations[]
Durations for notes in "The Wheels on the Bus".
Definition Songs.h:67
void playSong(int buzzerPin, int songNum)
Plays the song associated with the given song number using the provided buzzer pin.
Definition Songs.h:99
int song1Notes[]
Frequency values for notes in "Twinkle Twinkle Little Star".
Definition Songs.h:16
int song2NoteDurations[]
Durations for notes in "Mary Had a Little Lamb".
Definition Songs.h:48