Pages: [1]   Go Down
Author Topic: Timer Is stopping all other activty - Help Request (Solved)  (Read 378 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am trying to create a timer that will keep a fan on and leave it on until a 1 minute period has passed, then turn it off.
Once the fan has turn on ,it must stay on for a fixed time of 1 minute before shutting off


I just posted the timer portion, as the full sketch is to large.

The code below works but, while the fan is on and the timer is counting, nothing else is responsive.

What am i doing wrong?

Any help would be appreciated
Thanks
Joe

Code:
//*************TIMER CHECK**********************************
//If conditions are true turn on the A3 fan until 1 minute has past then shutoff of A3  are true...

if(rffan == HIGH) // status for temperature sensor 2  (temp2)
{
  
  //record start time...
  start_time = millis();
  Serial.println("start_time");
  Serial.println(start_time);

  //turn on A3 fan, turn normal temp led off and high temp led on

  // digitalWrite(A3, HIGH);  // this is the temp2 fan
  digitalWrite(A2,LOW); // BLUE LED off- NORMAL temp
  digitalWrite(9,HIGH); // HIGH TEMP LED

  //Continuosly check for finish time...
  do
  {

    current_time = millis();
    elapsed_time = current_time - start_time;
    Serial.println("counting");
    Serial.println(elapsed_time);
  }
  while(elapsed_time < 60000); // (1min) * (60s/min) * (1000ms/s)  

}
//turn OFF A3 fan if the count has been met
if (elapsed_time > 60000)
{
  digitalWrite(A3, LOW);  // Turn off A3  temp2 fan
}
Serial.println("time complete");
Serial.println(elapsed_time);



// ===========end ===TIMER=================================

« Last Edit: April 30, 2012, 12:58:01 pm by joeman » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your do/while statement is a redefinition of the delay() function. Of course it stops all other activity.
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 179
Posts: 8067
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It's doing what you told it to:
Code:
 do
  {
    current_time = millis();
    elapsed_time = current_time - start_time;
    Serial.println("counting");
    Serial.println(elapsed_time);
  }
  while(elapsed_time < 60000); // (1min) * (60s/min) * (1000ms/s)  

"DO (recalculate elapsed time) UNTIL (elapsed time >= 1 minute)"

What you probably want to do is:
    If the fan is ON and elapsed time is >= 1 minute
        turn fan off.
   do other stuff

This will check elapsed time each time through loop() and turn the fan off at the right time.  It doesn't take long so other stuff gets done.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Jr. Member
**
Karma: 0
Posts: 58
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the replies

johnwasser,

Changed the code as per  your suggestion / info 
Works!



Code:
 
  if (rffan == HIGH) // if temp2 went high then rffan is high  over temp occurred - start  counting
 {
    digitalWrite(9,HIGH); // Turn ON HIGH TEMP ALARM
    //record start time)..
    //start_time = millis();
    current_time = millis();
    elapsed_time = current_time - start_time;
    Serial.println("counting");
    Serial.println(elapsed_time);
   
 }

if ((rffan == HIGH) && (elapsed_time >= 60000)) // fan on and 1 minute check reached?
{
Serial.println("A3FAN OFF");
Serial.println(elapsed_time);
digitalWrite(A3, LOW);  // Turn off A3  temp2 fan

rffan =LOW; // reset temp2 status to normal temperature condition
}
Logged

Pages: [1]   Go Up
Jump to: