multiple BlinkWithoutDelays allowed ?

I need to use the normal BlinkWithoutDelay procedure for a 1 second countdown, in the usual manner, which is working.

I also need in the same sketch, to be able to sound a hooter for 4 seconds ( “horn” ) or for 2 seconds ( " toot" )

Can I use multiple BlinkWithoutDelays with separately defined previous times i.e.

long previousMillis = 0;        // will store last time  updated
long previoustootMillis = 0;        // will store last time toot was updated
long previoushornMillis = 0;        // will store last time horn was updated
long interval = 1000;           // interval countdowntimer (milliseconds)
long intervaltoot = 2000;           // interval at which to toot (milliseconds)
long intervalhorn = 4000;           // interval to sound horn (milliseconds)

with the countdown timer as :-

[code]if (T >= 0 && pause == 0 ) {
    unsigned long currentMillis = millis();

    if(currentMillis - previousMillis > interval) {
      // save the last time you counted 
      previousMillis = currentMillis;   

      T -- ;

[/code]

and the hooters:-

if (toot ==1 ) { 
   
    horn=1;   // switch on horn
    unsigned long currentMillis = millis();
    if(currentMillis - previoustootMillis > intervaltoot) {
      // save the last time you tooted 
      previoustootMillis = currentMillis;   
      horn = 0 ;  // switch off horn after intervaltoot
      toot = 0; // reset toot flag
    }
 }



if ( T <= 0 && pause == 0 ) //counted to 00 and not yet paused
{    
    horn=1;   // switch on horn
    unsigned long currentMillis = millis();
    if(currentMillis - previoushornMillis > intervalhorn) {
      // save the last time sounded horn 
      previoushornMillis = currentMillis;   
      horn = 0 ;  // switch off horn after intervaltoot

  pause = 1;   
    }
}

You could have tried it in less time than it took to post.

Please post your whole sketch as that is easier to see how it works.

Note: millis() returns an unsigned long so previousMillis etc should be unsigned too - millis() - Arduino Reference

I did and it didnt work :slight_smile:

Just wondered if I am doing something forbidden before I try to work out why it isn't working.

If I just asked if multiple BlinkWithoutDelays is allowed , someone would have said " post your code "

Thanks Rob I will try that.

The whole sketch needs a lot of tidying up , I was on it most of the night, and it is far too scruffy to post :slight_smile:

Multiple blink without delay is allowed and considered good programming practice as you are able to handle dozens of sensors and actuators with a single Arduino.

I asked to post your code as I cannot run snippets on my Arduino. I can make assumptions about how your code works and give an advice based on those assumptions. If I see the whole code the advice at least will not be based upon those assumptions.

Get a good sleep and we will see your code tomorrow :slight_smile:

Thanks for the info, I am on my dayjob project now, but will get back onto the Arduino stuff tonight.

Great signature quotation you have there BTW !