Go Down

Topic: Multiple FlashWithoutDelay (Read 402 times) previous topic - next topic

jeffingeorgetcr

I've a exhaust fan that run when the humidly is high when the exhaust fan on it should work for 3 minutes and should wait another 5 minutes to on. iam a beginner to this struggling for almost 2 days now. I tried some code but in incorrect loop dont know 

Code: [Select]
int ledPin =  2;      // the number of the LED pin
int ledState = LOW;             // ledState used to set the LED
unsigned long previousMillis2 = 0;
unsigned long previousMillis = 0;
long interval = 10000;           // in
long OnTime = 1000;           // milliseconds of on-time
long OffTime = 2000;          // milliseconds of off-time

void setup()
{
  
Serial.begin(9600);
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
}
 
void loop()
{

  unsigned long currentMillis2 = millis();
 
  if(currentMillis2 - previousMillis2 > interval) {
    // save the last time you blinked the LED

 
  
  // check to see if it's time to change the state of the LED
  Serial.print("hellohh ");
  unsigned long currentMillis = millis();
 
  if((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
  {
     Serial.print("hellohh2 ");
    ledState = LOW;  // Turn it off
    previousMillis = currentMillis;  // Remember the time
    digitalWrite(ledPin, ledState);  // Update the actual LED
  }
  else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
  {
     Serial.print("hellohh 3");
    ledState = HIGH;  // turn it on
    previousMillis = currentMillis;  
    previousMillis2 = 0; // Remember the time
    digitalWrite(ledPin, ledState);    // Update the actual LED
    
  }
  }}
  
  
 
  

 

lesept

This line

Code: [Select]
unsigned long currentMillis = millis () ;

creates a local variable, and this may be the cause of your problem. Make it a global variable and see if it is better.

If not, explain exactly what you want to do, as I didn't understand... 
A force d'essayer on finit par réussir... Donc, plus ça rate, plus on a de chances que ça marche (proverbe Sharduinok).

Go Up