-1

The best way to explain my problem is in form of code...

    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
}
}

Maybe you can give me some suggestions to my coding problems.? I wrote them inside the code descriptions.

  • 1
    WHy do you have 3 definitions of loop() in your code, is it a copy/paste issue? – jfpoilpret Nov 9 '14 at 14:48
0

Halo, thank you for ansering anything.. I got the loop loop loop thing now runin..

So its about playing an Audiofile if hookon == LOW ........ check it out :-)

The code now looks like this.

const int ringerPin = A0;
const int offhook = A4;
const int onhook = A5;
double beginRing = -40000;

void setup(){
    pinMode(ringerPin, OUTPUT);
    pinMode(offhook, INPUT);
    pinMode(onhook, INPUT);
    randomSeed(analogRead(0)); // this starts Arduino's random number generator
}

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){
    delay (randCall);
    beginRing = Time.elapsedTime;
    while(Time.elapsedTime - beginRing <= 30000 && digitalRead(hookon) == HIGH){
      //turn any audio off???
      for(int x = 0; x < 15; x++){
        digitalWrite(ringerPin, HIGH);   // turn the solenoid on (HIGH is the voltage level)
        delay(50);                           // wait for 50 msec
        digitalWrite(ringerPin, LOW);    // turn the solenoid off by making the voltage LOW
        delay(80);                          // wait for 50 msec
      }
      delay(2500);
    }
  }
  if(Time.elapsedTime - beginRing <= 30000){
    //play one randomly choosen audiofile out of 10
  }
}

So, now its about to stop any sound if the hookon is HIGH and to play the randomly choosen file 1 out of 10 if the hookon is LOW (its in the code as description...there i need the right comands)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.