-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCG_Bot_Buzzer_Play_Melody.ino
52 lines (36 loc) · 2.09 KB
/
CG_Bot_Buzzer_Play_Melody.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
int noteDuration; // Initialize variable to hold the duration of each note
void setup()
{
pinMode(A4, OUTPUT); // Set pin A4 as an output for the buzzer connection
}
void loop()
{
noteDuration = 1000 / 8; // Set note duration to an eighth note (1000ms divided by 8)
tone(A4, 196); // Play a note at 196 Hz frequency on the buzzer
delay(noteDuration); // Wait for the note to complete its duration
delay(noteDuration * 1.6); // Additional pause after the note, for rhythm
noteDuration = 1000 / 8; // Set note duration again to an eighth note
tone(A4, 196); // Play the same note at 196 Hz again
delay(noteDuration); // Wait for the note duration
delay(noteDuration * 1.6); // Additional pause for rhythm
noteDuration = 1000 / 4; // Set note duration to a quarter note (1000ms divided by 4)
tone(A4, 220); // Play a note at 220 Hz
delay(noteDuration); // Wait for the note duration
delay(noteDuration * 1.6); // Additional pause for rhythm
noteDuration = 1000 / 4; // Set note duration to a quarter note
tone(A4, 196); // Play a note at 196 Hz
delay(noteDuration); // Wait for the note duration
delay(noteDuration * 1.6); // Additional pause for rhythm
noteDuration = 1000 / 4; // Set note duration to a quarter note
tone(A4, 262); // Play a note at 262 Hz
delay(noteDuration); // Wait for the note duration
delay(noteDuration * 1.6); // Additional pause for rhythm
noteDuration = 1000 / 2; // Set note duration to a half note (1000ms divided by 2)
tone(A4, 247); // Play a note at 247 Hz
delay(noteDuration); // Wait for the note duration
delay(noteDuration * 1.6); // Additional pause for rhythm
noteDuration = 1000 / 8; // Set note duration back to an eighth note
tone(A4, 196); // Play the final note at 196 Hz
delay(noteDuration); // Wait for the note duration
// Loop will repeat, playing the sequence again
}