用copilot寫馬力歐音效程式

 





// 馬利兄弟主題曲的頻率和持續時間
int melody[] = {
  262, 262, 262, 196, 262, 330, 392, 0, 196, 220, 247, 233, 220, 196, 262, 0, 392, 370, 349, 311, 349, 330, 294, 311, 330, 0, 262, 262, 262, 196, 262, 330, 392, 0, 196, 220, 247, 233, 220, 196, 262, 0, 392, 370, 349, 311, 349, 330, 294, 311, 330
};
int noteDurations[] = {
  8, 8, 8, 8, 8, 8, 4, 4, 8, 8, 8, 8, 8, 8, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 8, 8, 8, 8, 8, 8, 8, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4
};

void setup() {
  // 將數字腳設置為輸出
  pinMode(8, OUTPUT);
}

void loop() {
  for (int thisNote = 0; thisNote < 51; thisNote++) {
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    // 計算音符之間的間隔時間
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);

    // 停止播放這個音符
    noTone(8);
  }
}


留言