解释我的问题的最好方法是使用codeform。
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
}
}如果有人能就我的编码问题给我一些建议,我将不胜感激。我把它们写在代码描述里面。
发布于 2014-11-10 00:43:46
loop()不是一种创建循环的方法。loop()是Arduino在可能的情况下反复调用的函数。
要创建循环,请使用while或for。您可以将loop()函数看作是while(true)循环的主体。
也就是说,你可能不应该使用循环来做你想要做的事情。有一个名为millis()的有用函数,它返回自设备打开以来的毫秒数。该值每隔50天溢出一次。您将需要处理它,但我建议您编写loop()函数来检查是否经过了足够的时间,然后执行它应该执行的操作。有关示例,请参阅this。
https://stackoverflow.com/questions/26829131
复制相似问题