如果信号仍然有效,如何停止循环
我有两个带接线的输入,第一个,检测门打开,并播放声音 1,当门关闭时,该声音关闭。
第二个声音是打开发动机汽车时的欢迎声音,但我对第二个声音有问题,因为它会永远循环播放欢迎声音,因为发动机已打开。
每次发动机开始工作时,我都需要播放欢迎声,但只有一次,输入信号永远不会切断,因为发动机是打开的,只有当发动机关闭时才会切断。
代码:
# 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 ();
}
}
我怎样才能停止循环?
i have two inputs with wiring, the first, detect doors opens, and play sound 1, this sound turn off, when closed its doors.
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以使用标志 as
但不要忘记在关闭引擎时将 iot 设置为 false
u can use flag as
but dont forget to put iot as false when turn the engine off