Загрузка данных



const int buzzerPin = 8;

struct Note {
  int frequency;
  int duration;
};

// Оригинальная мелодия в драматичном военном стиле
// Частоты указаны в герцах, длительности — в миллисекундах.
const Note melody[] = {
  // Вступление
  {440, 300}, {587, 420}, {698, 300}, {880, 600},
  {784, 250}, {698, 250}, {587, 450}, {440, 500},
  {0, 150},

  {523, 300}, {698, 420}, {880, 300}, {784, 600},
  {698, 250}, {659, 250}, {587, 650},
  {0, 200},

  // Маршевый мотив
  {294, 450}, {349, 300}, {440, 450}, {587, 600},
  {523, 300}, {466, 300}, {440, 550},
  {392, 300}, {440, 300}, {523, 650},
  {0, 150},

  {349, 450}, {440, 300}, {523, 450}, {698, 600},
  {659, 250}, {698, 250}, {784, 450}, {880, 650},
  {0, 180},

  // Кульминация
  {587, 300}, {698, 300}, {880, 450}, {1047, 750},
  {932, 300}, {880, 300}, {698, 600},
  {784, 300}, {698, 300}, {659, 450}, {880, 650},

  // Финальная фраза
  {784, 250}, {698, 250}, {659, 400}, {587, 800},
  {523, 300}, {440, 300}, {392, 500}, {294, 900},
  {0, 500}
};

void setup() {
  pinMode(buzzerPin, OUTPUT);
}

void loop() {
  int count = sizeof(melody) / sizeof(melody[0]);

  for (int i = 0; i < count; i++) {
    if (melody[i].frequency > 0) {
      tone(buzzerPin,
           melody[i].frequency,
           melody[i].duration);
    } else {
      noTone(buzzerPin);
    }

    delay(melody[i].duration);
    noTone(buzzerPin);

    // Небольшой промежуток между нотами
    delay(35);
  }

  delay(2500);
}