int pin = 12;// ブザーを接続したピン番号
int state = 0;

void setup() {
  pinMode(9,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(13,INPUT);//スイッチを13番ピンに接続
}


void loop() {
  state = digitalRead(13);


  if(state == 0){ //13番ピンに接続されたスイッチがおされたら
     tone(pin,262,200); // ド
     
     digitalWrite(9,HIGH);
     digitalWrite(2,HIGH);
     delay(600);
     digitalWrite(9,LOW);
     digitalWrite(2,LOW);
     delay(10);

     tone(pin,294,200);// レ

     digitalWrite(3,HIGH);
     delay(200);
     digitalWrite(3,LOW);
     delay(10);
     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(500);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,262,200);// ド

     digitalWrite(9,HIGH);
     digitalWrite(2,HIGH);
     delay(200);
     digitalWrite(9,LOW);
     digitalWrite(2,LOW);
     delay(10);
     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(400);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,262,200);// ド

     digitalWrite(9,HIGH);
     digitalWrite(2,HIGH);
     delay(400);
     digitalWrite(9,LOW);
     digitalWrite(2,LOW);
     delay(10);

     tone(pin,330,200); // ミ

     digitalWrite(4,HIGH);
     delay(600);
     digitalWrite(4,LOW);
     delay(10); 

     tone(pin,294,200);// レ

     digitalWrite(3,HIGH);
     delay(600);
     digitalWrite(3,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(200);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(200);
     digitalWrite(5,LOW);
     delay(10); 

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(200);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(200);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,294,200);// レ

     digitalWrite(3,HIGH);
     delay(200);
     digitalWrite(3,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(1200);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(600);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(200);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,392,200);  // ソ

     digitalWrite(6,HIGH);
     delay(500);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(200);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(400);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(400);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(600);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(600);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(200);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,440,200);// ラ

     digitalWrite(7,HIGH);
     delay(200);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,440,200);  // ラ

     digitalWrite(7,HIGH);
     delay(200);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(200);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(200);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,440,200);// ラ

     digitalWrite(7,HIGH);
     delay(1200);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(600);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,262,200);// ド

     digitalWrite(9,HIGH);
     digitalWrite(2,HIGH);
     delay(200);
     digitalWrite(9,LOW);
     digitalWrite(2,LOW);
     delay(10);

     tone(pin,294,200);// レ

     digitalWrite(3,HIGH);
     delay(200);
     digitalWrite(3,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(200);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(200);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(200);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,440,200);// ラ

     digitalWrite(7,HIGH);
     delay(1200);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,440,200);// ラ

     digitalWrite(7,HIGH);
     delay(600);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,294,200);// レ

     digitalWrite(3,HIGH);
     delay(200);
     digitalWrite(3,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(200);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(200);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(200);
     digitalWrite(6,LOW);
     delay(10);
     
     tone(pin,440,200);// ラ

     digitalWrite(7,HIGH);
     delay(200);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,494,200);// シ

     digitalWrite(8,HIGH);
     delay(1200);
     digitalWrite(8,LOW);
     delay(10);

     tone(pin,494,200);// シ

     digitalWrite(8,HIGH);
     delay(600);
     digitalWrite(8,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(200);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(200);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(200);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,440,200);// ラ

     digitalWrite(7,HIGH);
     delay(200);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,494,200);// シ

     digitalWrite(8,HIGH);
     delay(200);
     digitalWrite(8,LOW);
     delay(10);

     tone(pin,523,800);// ド

     digitalWrite(9,HIGH);
     digitalWrite(2,HIGH);
     delay(1200);
     digitalWrite(9,LOW);
     digitalWrite(2,LOW);
     delay(10);

     tone(pin,494,400);// シ

     digitalWrite(8,HIGH);
     delay(400);
     digitalWrite(8,LOW);
     delay(10);

     tone(pin,466,400);// シ♭

     digitalWrite(7,HIGH);
     digitalWrite(8,HIGH);
     delay(400);
     digitalWrite(7,LOW);
     digitalWrite(8,LOW);
     delay(10);

     tone(pin,440,800);// ラ

     digitalWrite(7,HIGH);
     delay(800);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,349,800);// ファ

     digitalWrite(5,HIGH);
     delay(800);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,494,800);// シ

     digitalWrite(8,HIGH);
     delay(800);
     digitalWrite(8,LOW);
     delay(10);

     tone(pin,392,800);// ソ

     digitalWrite(6,HIGH);
     delay(800);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,523,800);// ド

     digitalWrite(2,HIGH);
     digitalWrite(9,HIGH);
     delay(1200);
     digitalWrite(2,LOW);
     digitalWrite(9,LOW);
     delay(10);

     tone(pin,262,200);// ド   finale

     digitalWrite(2,HIGH);
     digitalWrite(9,HIGH);
     delay(200);
     digitalWrite(2,LOW);
     digitalWrite(9,LOW);
     delay(10);

     tone(pin,294,200);// レ

     digitalWrite(3,HIGH);
     delay(200);
     digitalWrite(3,LOW);
     delay(10);

     tone(pin,330,200);// ミ

     digitalWrite(4,HIGH);
     delay(200);
     digitalWrite(4,LOW);
     delay(10);

     tone(pin,349,200);// ファ

     digitalWrite(5,HIGH);
     delay(200);
     digitalWrite(5,LOW);
     delay(10);

     tone(pin,392,200);// ソ

     digitalWrite(6,HIGH);
     delay(200);
     digitalWrite(6,LOW);
     delay(10);

     tone(pin,440,200);// ラ

     digitalWrite(7,HIGH);
     delay(200);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,494,200);// シ

     digitalWrite(7,HIGH);
     delay(200);
     digitalWrite(7,LOW);
     delay(10);

     tone(pin,523,200);// ド

     digitalWrite(9,HIGH);
     digitalWrite(8,HIGH);
     digitalWrite(7,HIGH);
     digitalWrite(6,HIGH);
     digitalWrite(5,HIGH);
     digitalWrite(4,HIGH);
     digitalWrite(3,HIGH);
     digitalWrite(2,HIGH);
     delay(400);

     digitalWrite(9,LOW);
     digitalWrite(8,LOW);
     digitalWrite(7,LOW);
     digitalWrite(6,LOW);
     digitalWrite(5,LOW);
     digitalWrite(4,LOW);
     digitalWrite(3,LOW);
     digitalWrite(2,LOW);
     delay(70);


     tone(pin,392,200);// ソ
     digitalWrite(9,HIGH);
     digitalWrite(8,HIGH);
     digitalWrite(7,HIGH);
     digitalWrite(6,HIGH);
     digitalWrite(5,HIGH);
     digitalWrite(4,HIGH);
     digitalWrite(3,HIGH);
     digitalWrite(2,HIGH);
     delay(400);

     digitalWrite(9,LOW);
     digitalWrite(8,LOW);
     digitalWrite(7,LOW);
     digitalWrite(6,LOW);
     digitalWrite(5,LOW);
     digitalWrite(4,LOW);
     digitalWrite(3,LOW);
     digitalWrite(2,LOW);
     delay(70);

     tone(pin,523,800);// ド

     digitalWrite(9,HIGH);
     digitalWrite(8,HIGH);
     digitalWrite(7,HIGH);
     digitalWrite(6,HIGH);
     digitalWrite(5,HIGH);
     digitalWrite(4,HIGH);
     digitalWrite(3,HIGH);
     digitalWrite(2,HIGH);
     delay(1200);

     digitalWrite(9,LOW);
     digitalWrite(8,LOW);
     digitalWrite(7,LOW);
     digitalWrite(6,LOW);
     digitalWrite(5,LOW);
     digitalWrite(4,LOW);
     digitalWrite(3,LOW);
     digitalWrite(2,LOW);
     delay(70);

}

}