小星星

 int melody[] = {

  262, 262, 392, 392, 440, 440, 392, 0, 349, 349, 330, 330, 294, 294, 262, 0,

  392, 392, 349, 349, 330, 330, 294, 0, 392, 392, 349, 349, 330, 330, 294, 0,

  262, 262, 392, 392, 440, 440, 392, 0, 349, 349, 330, 330, 294, 294, 262

};

int noteDurations[] = {

  4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4,

  4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2, 4, 4,

  4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 2

};


void setup() {

  pinMode(8, OUTPUT);

}


void loop() {

  for (int thisNote = 0; thisNote < 47; thisNote++) {

    int noteDuration = 1000 / noteDurations[thisNote];

    tone(8, melody[thisNote], noteDuration);


    int pauseBetweenNotes = noteDuration * 1.30;

    delay(pauseBetweenNotes);


    noTone(8);

  }

}


留言