简体   繁体   English

如果信号仍然有效,如何停止循环

[英]How stop a loop, if the signal is still active

i have two inputs with wiring, the first, detect doors opens, and play sound 1, this sound turn off, when closed its doors.我有两个带接线的输入,第一个,检测门打开,并播放声音 1,当门关上时,这个声音关闭。

The second sound, is welcome sound when turn on the engine car, but i have problem with the second sound, because it plays loop forever with welcome the sound because the engine is turn on.第二个声音是打开发动机汽车时的欢迎声音,但我对第二个声音有问题,因为它会永远循环播放欢迎声音,因为发动机已打开。

I need to play the welcome sound every time the engine is beginning to work, but only once, the input signal never cut off, because the engine is turn on, it only cuts off when the engine is off.每次引擎开始工作我都需要播放欢迎音,但只有一次,输入信号永远不会切断,因为引擎是打开的,只有在引擎关闭时才会切断。

The code:代码:

# define ACTIVATED LOW

int btndoor = 7;
int btnwelcome = 6;

void setup()
{
  pinMode(btndoor, INPUT);
  digitalWrite(btnpuerta,HIGH);

  pinMode(btnwelcome, INPUT);
  digitalWrite(btnwelcome,HIGH);

}

void loop(){
  if (digitalRead(btndoor) == ACTIVATED) {
    myDFPlayer.play(1);
    delay(2500);
    }

  if (digitalRead(btnwelcome) == ACTIVATED) {
          myDFPlayer.play (5);
          delay (2000);
          myDFPlayer.stop ();     
     
    }

}

How i can stop loop?我怎样才能停止循环?

u can use flag as你可以使用标志作为

if engine is on
 if flag ==  false
   play the sound 
   flag = true

but dont forget to put iot as false when turn the engine off但不要忘记在关闭引擎时将它设置为 false

turn engine off 
flag = false
if (digitalRead(btnpuerta) == ACTIVATED) {
    myDFPlayer.play(1);
    delay(2500);
    }

   if (digitalRead(btnwelcome) == ACTIVATED) {
       if (doneFlag == false) // fragmento para repetir el comando una sola vez
      {
          myDFPlayer.play (5);
          delay (2000);
          myDFPlayer.stop ();
          doneFlag = true;
      }
     
    }else{
      doneFlag = false;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM