int btn=3;
int buzzer=10;
int code[]={1,2,1,2};
int input[4];
int step=0;
int melody[]={262,330,392,523,659,784};
void setup(){
pinMode(btn,INPUT_PULLUP);
pinMode(buzzer,OUTPUT);
}
void loop(){
if(digitalRead(btn)==LOW){
delay(50);
int time=0;
while(digitalRead(btn)==LOW){
delay(10);
time+=10;
}
input[step]=(time>500)?2:1;
tone(buzzer,800,100);
step++;
if(step>=4){
bool ok=true;
for(int i=0;i<4;i++) if(input[i]!=code[i]) ok=false;
if(ok){
for(int i=0;i<6;i++){
tone(buzzer,melody[i],200);
delay(250);
}
}else{
tone(buzzer,200,1000);
}
step=0;
delay(1000);
}
}
}