馬力歐音樂

 // 超級馬利兄弟主題曲(精準版)

int melody[] = {

  660, 660, 0, 660, 0, 520, 660, 0, 440, 0, 0, 520, 0,

  440, 0, 0, 349, 0, 392, 0, 440, 0, 0, 349, 0, 392, 0, 440,

  0, 494, 494, 494, 0, 392, 0, 440, 0, 349, 0, 392, 0, 330,

  0, 349, 0, 294, 0, 330, 0, 262, 0, 294, 0, 220, 0, 262

};


int noteDurations[] = {

  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,

  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,

  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,

  100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100

};


void setup() {

  pinMode(8, OUTPUT);

}


void loop() {

  for (int thisNote = 0; thisNote < sizeof(melody)/sizeof(melody[0]); thisNote++) {

    int note = melody[thisNote];

    int duration = noteDurations[thisNote];


    if (note > 0) {

      tone(8, note, duration);

    }


    delay(duration * 1.3);

    noTone(8);

  }


  // 播放完畢後暫停一段時間再重播

  delay(2000);

}


留言