#define tonePin 12 // Пин для динамика
/*
const int melodyOpen[] = { 659.255, 659.255, 659.255, 523.251, 659.255, 783.991, 391.995, 523.251, 391.995, 329.628, 440, 493.883, 466.164, 440, 391.995, 659.255, 783.991, 880, 698.456, 783.991, 659.255, 523.251, 587.33, 987.767, 783.991, 680.255, 698.456, 622.254, 680.255, 415.305, 466.164, 523.251, 440, 523.251, 587.33, 783.991, 739.989, 729.989, 587.33, 659.255, 1046.502, 1046.502, 1046.502 }; // Ноты для мелодии "Открыть"
const int durationsOpen[] = { 300, 300, 160, 160, 300, 300, 300, 300, 300, 300, 300, 300, 160, 300, 300, 300, 300, 300, 160, 160, 300, 160, 160, 160, 300, 300, 160, 300, 160, 300, 300, 300, 300, 300, 300, 300, 300, 160, 300, 300, 300, 160, 300 }; // Длительности нот
const int pausesOpen[] = { 35, 35, 50, 35, 35, 350, 200, 35, 35, 200, 35, 35, 35, 200, 35, 35, 35, 35, 35, 200, 35, 35, 35, 35, 35, 35, 35, 35, 200, 35, 35, 35, 35, 35, 200, 35, 35, 35, 35, 200, 35, 35, 0 }; // Паузы между нотами
const int melodyClose[] = { 392, 330, 294, 262, 0 }; // Ноты для мелодии "Закрыть"
const int durationsClose[] = { 400, 300, 500, 200, 0 };
const int pausesClose[] = { 150, 100, 200, 100, 0 };
const int melodyError[] = { 330, 330, 330, 0, 294 };
const int durationsError[] = { 300, 300, 300, 0, 300 };
const int pausesError[] = { 100, 100, 150, 0, 100 };
*/
void setup() {
pinMode(tonePin, OUTPUT);
}
void loop() {
tone(tonePin, 1318, 12.75);
delay(14.1666666667);
tone(tonePin, 587, 154.5);
delay(171.666666667);
tone(tonePin, 1174, 6.75);
delay(7.5);
delay(1.66666666667);
tone(tonePin, 554, 182.25);
delay(202.5);
delay(2.5);
delay(2.5);
tone(tonePin, 1108, 20.25);
delay(22.5);
delay(182.5);
tone(tonePin, 987, 0.75);
delay(0.833333333333);
tone(tonePin, 493, 14.25);
delay(15.8333333333);
tone(tonePin, 440, 252.0);
delay(280.0);
tone(tonePin, 880, 7.5);
delay(8.33333333333);
delay(76.6666666667);
delay(4.16666666667);
delay(406.666666667);
delay(0.833333333333);
tone(tonePin, 880, 9.75);
delay(10.8333333333);
tone(tonePin, 440, 1.5);
delay(1.66666666667);
tone(tonePin, 493, 299.25);
delay(332.5);
tone(tonePin, 987, 9.75);
delay(10.8333333333);
delay(42.5);
delay(1.66666666667);
delay(394.166666667);
delay(0.833333333333);
tone(tonePin, 987, 7.5);
delay(8.33333333333);
tone(tonePin, 493, 13.5);
delay(15.0);
tone(tonePin, 554, 447.75);
delay(497.5);
tone(tonePin, 1108, 15.75);
delay(17.5);
delay(69.1666666667);
delay(0.833333333333);
delay(195.833333333);
delay(2.5);
tone(tonePin, 493, 8.25);
delay(9.16666666667);
tone(tonePin, 987, 3.0);
delay(3.33333333333);
delay(183.333333333);
delay(4.16666666667);
tone(tonePin, 440, 3.0);
delay(3.33333333333);
tone(tonePin, 880, 6.0);
delay(6.66666666667);
tone(tonePin, 987, 164.25);
delay(182.5);
delay(2.5);
delay(2.5);
tone(tonePin, 493, 13.5);
delay(15.0);
tone(tonePin, 1108, 162.75);
delay(180.833333333);
delay(5.0);
tone(tonePin, 554, 14.25);
delay(15.8333333333);
tone(tonePin, 1174, 165.0);
delay(183.333333333);
tone(tonePin, 587, 3.0);
delay(3.33333333333);
tone(tonePin, 659, 446.25);
delay(495.833333333);
tone(tonePin, 1318, 27.0);
delay(30.0);
delay(74.1666666667);
delay(3.33333333333);
delay(200.0);
delay(1.66666666667);
tone(tonePin, 1244, 3.75);
delay(4.16666666667);
tone(tonePin, 622, 3.0);
delay(3.33333333333);
delay(394.166666667);
delay(1.66666666667);
tone(tonePin, 1318, 6.75);
delay(7.5);
tone(tonePin, 659, 14.25);
delay(15.8333333333);
delay(374.166666667);
tone(tonePin, 554, 5.25);
delay(5.83333333333);
tone(tonePin, 1108, 6.0);
delay(6.66666666667);
tone(tonePin, 987, 285.0);
delay(316.666666667);
tone(tonePin, 493, 5.25);
delay(5.83333333333);
delay(56.6666666667);
delay(2.5);
tone(tonePin, 493, 278.25);
delay(309.166666667);
delay(90.0);
delay(0.833333333333);
delay(196.666666667);
delay(4.16666666667);
tone(tonePin, 659, 0.75);
delay(0.833333333333);
tone(tonePin, 1318, 16.5);
delay(18.3333333333);
delay(175.0);
tone(tonePin, 1174, 2.25);
delay(2.5);
delay(0.833333333333);
tone(tonePin, 587, 7.5);
delay(8.33333333333);
tone(tonePin, 554, 147.75);
delay(164.166666667);
tone(tonePin, 1108, 21.0);
delay(23.3333333333);
delay(4.16666666667);
delay(203.333333333);
delay(0.833333333333);
tone(tonePin, 493, 3.0);
delay(3.33333333333);
tone(tonePin, 987, 9.0);
delay(10.0);
tone(tonePin, 440, 341.25);
delay(379.166666667);
delay(6.66666666667);
delay(0.833333333333);
tone(tonePin, 880, 0.75);
delay(0.833333333333);
tone(tonePin, 369, 350.25);
delay(389.166666667);
delay(1.66666666667);
delay(0.833333333333);
tone(tonePin, 739, 1.5);
delay(1.66666666667);
delay(390.833333333);
tone(tonePin, 554, 5.25);
delay(5.83333333333);
tone(tonePin, 1108, 15.0);
delay(16.6666666667);
delay(383.333333333);
tone(tonePin, 349, 21.75);
delay(24.1666666667);
tone(tonePin, 698, 11.25);
delay(12.5);
tone(tonePin, 369, 647.25);
delay(719.166666667);
tone(tonePin, 739, 9.0);
delay(10.0);
delay(44.1666666667);
delay(1.66666666667);
tone(tonePin, 739, 351.75);
delay(390.833333333);
tone(tonePin, 369, 0.75);
delay(0.833333333333);
}
/*
void playMelody(int type) {
const int *melody;
const int *noteDurations;
const int *notePauses;
int size;
switch (type) {
case 1:
melody = melodyOpen;
noteDurations = durationsOpen;
notePauses = pausesOpen;
size = sizeof(melodyOpen) / sizeof(melodyOpen[0]);
break;
case 2:
melody = melodyClose;
noteDurations = durationsClose;
notePauses = pausesClose;
size = sizeof(melodyClose) / sizeof(melodyClose[0]);
break;
case 3:
melody = melodyError;
noteDurations = durationsError;
notePauses = pausesError;
size = sizeof(melodyError) / sizeof(melodyError[0]);
break;
}
for (int i = 0; i < size; i++) {
int noteDuration = noteDurations[i]; // Длительность ноты
int notePause = notePauses[i]; // Пауза после ноты
if (melody[i] == 0) {
delay(noteDuration); // Пауза
} else {
tone(BUZZER_PIN, melody[i], noteDuration);
delay(noteDuration); // Задержка для проигрывания ноты
}
delay(notePause); // Пауза между нотами
}
}
*/