Arduino open door (outdoor) tonemelody My problem lies in the fact that I can not stop the "void loop" function and more accurately "StatInDoor". I have to make sure that the "ButtonOpenDoor" works independently of "ButtonCall". If someone presses the "ButtonCall" button then the "ButtonOpenDoor" button must work in progress, and if the "ButtonCall" button is pressed, the "ButtonOpenDoor" button must stop playing the melody.

My idea for this this:

int StatOutDoor = digitalRead(ButtonCall &amp;&amp; ButtonOpenDoor);


or:

if(StatOutDoor == LOW &amp;&amp; StatInDoor = LOW){
   PlayMelody();
}


But it does not work :(

Full code:

#include "pitches.h"

int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};
int ButtonCall = 4;
int buzzer = 8;
int ButtonOpenDoor = 7;
int RelayModule = 12;

void PlayMelody() {
  for (int thisNote = 0; thisNote &lt; 8; thisNote++) {
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(buzzer, melody[thisNote], noteDuration);
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    noTone(buzzer);
  }
}

void setup(){
  pinMode(ButtonCall, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(ButtonOpenDoor,INPUT);
  pinMode(RelayModule,OUTPUT);
}

void loop() {
  int StatOutDoor = digitalRead(ButtonCall); 
  if(StatOutDoor == LOW){
    PlayMelody();    
  }  
  int StatInDoor = digitalRead(ButtonOpenDoor);
  if (StatInDoor == HIGH) {
    digitalWrite(RelayModule, HIGH);
  } else {
    digitalWrite(RelayModule, LOW);
    delay(3300);
  }
}


Can someone help with this? (Sorry for my bad English).
I'm not quite sure I understand the logic of what you're asking. Your description is a little vague. Maybe if you provided more information about what the signals are, what they mean, and where they come from, it may help.

However - if you want the melody to play when both inputs are LOW you should change:

if(StatOutDoor == LOW &amp;&amp; StatInDoor = LOW){
      PlayMelody();    
} 


to:

if(StatOutDoor == LOW &amp;&amp; StatInDoor == LOW){
      PlayMelody();    
} 


Note the use of == not = to denote equality (= is assignment).

Also the use of a 3.3 second delay in your else will show everything down to a crawl when StatInDoor is HIGH.