|
//https://www.arduino.cc/en/Tutorial/toneMelody |
|
//Şamil Korkmaz, April 2020 |
|
const int buzzerPin = 3; //D3 |
|
#define B3 247 |
|
#define C4 262 |
|
#define D4 294 |
|
#define E4 330 |
|
#define F4 349 |
|
#define G4 392 |
|
#define A4 440 |
|
|
|
// notes in the melody: https://www.gitaregitim.net/wp-content/uploads/2020/04/23_Nisan_Kutlu_Olsun_DO.pdf |
|
int melody[] = { |
|
C4, D4, E4, D4, C4, D4, E4, D4, C4, |
|
G4, A4, G4, F4, E4, D4, F4, G4, F4, E4, D4, C4, |
|
C4, D4, E4, D4, C4, D4, E4, D4, C4, |
|
C4, D4, E4, D4, C4, D4, E4, D4, C4, |
|
G4, A4, G4, F4, E4, D4, F4, G4, F4, E4, D4, C4, |
|
C4, D4, E4, D4, C4, D4, E4, D4, C4, |
|
|
|
G4, F4, E4, D4, E4, F4, G4, A4, |
|
G4, F4, E4, D4, E4, F4, G4, |
|
G4, F4, E4, D4, E4, F4, G4, A4, |
|
G4, F4, E4, D4, C4, B3, C4, |
|
G4, F4, E4, D4, E4, F4, G4, A4, |
|
G4, F4, E4, D4, E4, F4, G4, |
|
G4, F4, E4, D4, E4, F4, G4, A4, |
|
G4, F4, E4, D4, C4, B3, C4 |
|
}; |
|
|
|
// note durations: 4 = quarter note, 8 = eighth note, etc.: |
|
int noteDurations[] = { |
|
6, 16, 8, 8, 4, 4, 4, 4, 2, |
|
8, 8, 4, 8, 8, 4, 8, 8, 4, 8, 8, 4, |
|
6, 16, 8, 8, 4, 4, 4, 4, 2, |
|
6, 16, 8, 8, 4, 4, 4, 4, 2, |
|
8, 8, 4, 8, 8, 4, 8, 8, 4, 8, 8, 4, |
|
6, 16, 8, 8, 4, 4, 4, 4, 2, |
|
|
|
6, 16, 8, 8, 6, 16, 8, 8, |
|
6, 16, 8, 8, 8, 8, 4, |
|
6, 16, 8, 8, 6, 16, 8, 8, |
|
6, 16, 8, 8, 8, 8, 4, |
|
6, 16, 8, 8, 6, 16, 8, 8, |
|
6, 16, 8, 8, 8, 8, 4, |
|
6, 16, 8, 8, 6, 16, 8, 8, |
|
6, 16, 8, 8, 8, 8, 4 |
|
}; |
|
|
|
void setup() { |
|
for (int iNote = 0; iNote < sizeof(melody)/sizeof(melody[0]); iNote++) { |
|
int noteDuration = 2000 / noteDurations[iNote]; |
|
tone(buzzerPin, melody[iNote], noteDuration); |
|
// to distinguish the notes, set a minimum time between them. |
|
// the note's duration + 30% seems to work well: |
|
int pauseBetweenNotes = noteDuration * 1.30; |
|
delay(pauseBetweenNotes); |
|
// stop the tone playing: |
|
noTone(8); |
|
} |
|
} |
|
|
|
void loop() { |
|
// no need to repeat the melody. |
|
} |