/
kaleo_way_down_we_go.ino
58 lines (49 loc) · 1.64 KB
/
kaleo_way_down_we_go.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
53
54
55
56
57
58
// -------------------------------------------------
// Copyright (c) 2024 HiBit <https://www.hibit.dev>
// -------------------------------------------------
#include "pitches.h"
#define BUZZER_PIN 9
int melody[] = {
NOTE_F4, NOTE_AS5, NOTE_GS4, NOTE_CS4, REST,
NOTE_AS5, NOTE_AS5, NOTE_CS6, NOTE_AS5, NOTE_AS5, NOTE_GS4, NOTE_F4,
NOTE_GS4, NOTE_AS5, NOTE_CS6, NOTE_AS5, NOTE_AS5, NOTE_GS4, NOTE_F4, NOTE_GS4,
NOTE_AS5, NOTE_CS6, NOTE_AS5, NOTE_AS5, NOTE_F5,
NOTE_DS5, NOTE_CS5, NOTE_AS5, NOTE_AS5, NOTE_AS5, NOTE_GS4, NOTE_F4, NOTE_GS4,
NOTE_AS5, NOTE_CS6, NOTE_AS5, NOTE_AS5, NOTE_GS4, NOTE_F4, NOTE_GS4,
NOTE_AS5, NOTE_CS6, NOTE_AS5, NOTE_AS5, NOTE_GS4, NOTE_F4, NOTE_GS4,
NOTE_AS5, NOTE_CS6, NOTE_AS5, NOTE_AS5, NOTE_F5,
NOTE_DS5, NOTE_CS5, NOTE_AS5, NOTE_AS5, NOTE_F5, NOTE_F5, NOTE_F5,
REST
};
int durations[] = {
8, 4, 4, 4, 2,
4, 4, 4, 2, 4, 4, 4,
4, 4, 4, 2, 4, 4, 4,
4, 4, 2, 4, 2,
8, 8, 4, 2, 4, 4, 4, 4,
4, 4, 2, 4, 4, 4, 4,
4, 4, 2, 4, 4, 4, 4,
4, 4, 2, 4, 2,
8, 8, 4, 4, 4, 2, 2,
1
};
void setup()
{
pinMode(BUZZER_PIN, OUTPUT);
}
void loop()
{
int size = sizeof(durations) / sizeof(int);
for (int note = 0; note < size; note++) {
//to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int duration = 1000 / durations[note];
tone(BUZZER_PIN, melody[note], duration);
//to distinguish the notes, set a minimum time between them.
//the note's duration + 30% seems to work well:
int pauseBetweenNotes = duration * 1.30;
delay(pauseBetweenNotes);
//stop the tone playing:
noTone(BUZZER_PIN);
}
}