         int pause = duration * 1.5; //音符の間で時間をあける
         delay(pause);
     }
-    return MODE1;
 }
 
-int music2(){
-    delay(500);
-    buttonState=1;
+void music2(){
     digitalWrite(0, LOW);
     digitalWrite(1, LOW);
     digitalWrite(2, LOW);

    digitalWrite(13, LOW);
}

const int MODE0=0;
const int MODE1=1;
const int MODE2=2;

int buttonState=1;
void loop() {
    static int next_mode = MODE0;
    if(next_mode==MODE0)      next_mode = start1();
    else if(next_mode==MODE1) next_mode = music1();
    else if(next_mode==MODE2) next_mode = music2();
}

int start1(){
    delay(500);
    buttonState=digitalRead(9); 
    if (buttonState ==LOW ) return MODE1;
    else{
        analogReference(INTERNAL);
        int x=analogRead(5);
        if(x<260){tone(8, 100,100);}
        else if(x<280){tone(8, 600,100);}
        else if(x<300){tone(8, 1100,100);}
        else if(x<320){tone(8, 1600,100);}
        else if(x<340){tone(8, 2100,100);}
        else if(x<360){tone(8, 2600,100);}
        else if(x<380){tone(8, 3100,100);}
        else if(x<400){tone(8, 3600,100);}
        else if(x<420){tone(8, 4100,100);}
        else if(x<440){tone(8, 4600,100);}
        else{tone(8, 5100,100);}
        delay(1000);
    }
    return MODE0;
}

int music1(){
    delay(500);
    buttonState=1;
    for (int thisNote = 0; thisNote < 82; thisNote++) { 
       buttonState=digitalRead(9); 
       if (buttonState ==LOW ) return MODE2;
       if(thisNote == 0){
            digitalWrite(5,LOW);
            digitalWrite(6,LOW);

    digitalWrite(13, LOW);

    for (int thisNote = 0; thisNote < 68; thisNote++) {
        digitalWrite(5,HIGH);
        digitalWrite(6,HIGH);
        digitalWrite(7,HIGH);
