-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathRAK18001_Buzzer.ino
120 lines (102 loc) · 3.08 KB
/
RAK18001_Buzzer.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
@file RAK18001_Buzzer.ino
@author rakwireless.com
@brief period buzzer test and play a funny song
@version 0.1
@date 2020-12-28
@copyright Copyright (c) 2020
**/
#include <Arduino.h>
#include <Adafruit_TinyUSB.h>
#define BUZZER_CONTROL WB_IO1
//This part is the note and rhythm of the song
#define NTC0 -1
#define NTC1 262
#define NTC2 294
#define NTC3 330
#define NTC4 350
#define NTC5 393
#define NTC6 441
#define NTC7 495
#define NTCL1 131
#define NTCL2 147
#define NTCL3 165
#define NTCL4 175
#define NTCL5 196
#define NTCL6 221
#define NTCL7 248
#define NTCH1 525
#define NTCH2 589
#define NTCH3 661
#define NTCH4 700
#define NTCH5 786
#define NTCH6 882
#define NTCH7 990
#define WHOLE 1
#define HALF 0.5
#define QUARTER 0.25
#define EIGHTH 0.125
#define SIXTEENTH 0.0625
int tune[] = //List the frequencies according to the spectrum
{
NTC5, NTC5, NTC6,
NTCH1, NTC6, NTC5, NTC6, NTCH1, NTC6, NTC5,
NTC3, NTC3, NTC3, NTC5,
NTC6, NTC6, NTC5, NTCH3, NTCH3, NTCH2, NTCH1,
NTCH2, NTCH1, NTCH2,
NTCH3, NTCH3, NTCH2, NTCH3, NTCH2, NTCH1, NTCH2, NTCH1, NTC6,
NTCH2, NTCH2, NTCH2, NTCH1, NTC6, NTC5,
NTC6, NTC5, NTC5, NTCH1, NTC6, NTC5, NTC1, NTC3,
NTC2, NTC1, NTC2,
NTC3, NTC5, NTC5, NTC3, NTCH1, NTC7,
NTC6, NTC5, NTC6, NTCH1, NTCH2, NTCH3,
NTCH3, NTCH2, NTCH1, NTC5, NTCH1, NTCH2, NTCH3,
NTCH2, NTC0, NTCH3, NTCH2,
NTCH1, NTC0, NTCH2, NTCH1, NTC6, NTC0,
NTCH2, NTC6, NTCH1, NTCH1, NTCH1, NTC6, NTC5, NTC3,
NTC5,
NTC5, NTC6, NTCH1, NTC7, NTC6,
NTCH3, NTCH3, NTCH3, NTCH3, NTCH2, NTCH2, NTCH1,
NTC6, NTCH3, NTCH2, NTCH1, NTCH2, NTCH1, NTC6,
NTCH1,
};
float durt[] = //List the beats according to the notation
{
HALF, QUARTER, QUARTER,
WHOLE + HALF, HALF, HALF, QUARTER, QUARTER, HALF, HALF,
WHOLE + WHOLE + WHOLE, HALF, QUARTER, QUARTER,
WHOLE + HALF, HALF, HALF, HALF, QUARTER, QUARTER, HALF,
WHOLE + WHOLE + WHOLE, HALF, HALF,
HALF, HALF, HALF, QUARTER, QUARTER, HALF, QUARTER, QUARTER, HALF,
HALF, HALF, HALF, QUARTER, QUARTER, WHOLE + WHOLE,
HALF, HALF, HALF, HALF, HALF, HALF, HALF, HALF,
WHOLE + WHOLE + WHOLE, HALF, HALF,
WHOLE + HALF, HALF, HALF, HALF, HALF, HALF,
WHOLE + HALF, HALF, WHOLE, HALF, QUARTER, QUARTER,
WHOLE + HALF, HALF, HALF, HALF, HALF, QUARTER, QUARTER,
WHOLE + WHOLE + WHOLE, HALF, QUARTER, QUARTER,
WHOLE, HALF, QUARTER, QUARTER, WHOLE, WHOLE,
HALF, HALF, HALF, HALF, WHOLE, QUARTER, QUARTER, HALF,
WHOLE + WHOLE + WHOLE + WHOLE,
HALF, HALF, HALF, HALF, WHOLE + WHOLE,
HALF, HALF, HALF, HALF, WHOLE + HALF, QUARTER, QUARTER,
WHOLE + HALF, HALF, WHOLE, QUARTER, QUARTER, QUARTER, QUARTER, WHOLE + WHOLE + WHOLE + WHOLE,
};
int length = 0;
void setup()
{
Serial.begin(115200);
while (!Serial) {};
pinMode(BUZZER_CONTROL, OUTPUT);
length = sizeof(tune) / sizeof(tune[0]); //Calculation length
}
void loop()
{
for (int x = 0; x < length; x++)
{
tone(BUZZER_CONTROL, tune[x]);
delay(500 * durt[x]); //Here it is used to adjust the delay according to the beat. The 500 index can be adjusted by myself. In this music, I find that 500 is more suitable.
noTone(BUZZER_CONTROL);
}
delay(2000);
}