【问题标题】:Arduino Lily Pad mp3, Loop in Loop in Loop with timingArduino Lily Pad mp3,带计时的循环中循环
【发布时间】:2014-11-09 14:15:57
【问题描述】:

解释我的问题的最佳方式是使用代码形式。

    const int ringerPin = A0;
    const int offhook = A4;
    const int onhook = A5;

    void setup(){
    pinMode(ringerPin, OUTPUT);
    pinMode(offhook, INPUT);
    pinMode(onhook, INPUT);
    randomSeed(analogRead(0));

  }

  int randCall = random(60000, 3600000); // generate a random number between 1 min and 60 min

//ring every 1 to 60 minutes if the phone is down (hookon) and dont ring if the phone is picked up (no hookon)
void loop()
{
  if (digitalRead(hookon) == HIGH)

void loop(){
delay(randCall);

      //i dont know how to let this loop below here run for 30 seconds.
 void loop()
    {
      //turn audio off - i dont know how to.
    for(int x = 0; x < 15; x++){
      digitalWrite(ringerPin, HIGH);   
      delay(50);                           
      digitalWrite(ringerPin, LOW);   
      delay(80); 
    }
    delay(2500);
    }
  else
    //play one randomly choosen audiofile out of 10 - i dont know how to
}
}

如果有人可以就我的编码问题给我一些建议,我将不胜感激。? 我将它们写在代码描述中。

【问题讨论】:

    标签: c++ random arduino nested-loops


    【解决方案1】:

    loop() 不是创建循环的方法。 loop() 是 Arduino 尽可能反复调用的函数。

    要创建循环,请使用 whilefor。您可以将loop() 函数视为while(true) 循环的主体。

    也就是说,您可能不应该为您正在尝试做的事情使用循环。有一个名为millis() 的有用函数返回自设备开启以来的毫秒数。该值每 50 天溢出一次。你需要处理这个问题,但我建议你编写loop() 函数来检查是否有足够的时间过去,然后做它应该做的事情。示例见this

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 2022-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多