Help with delay

Hi folks,

I need to implement a delay in such a way that if a variable is found to be true the output is 0 for 500ms. The output counter should be reset each time the variable is zero

The idea is that if the variable has noise, for example, goes from 1 to zero randomly the output will always be zero.

Any ideas?

Use variable for delay to describe ms.

if /something/
{VAR = 0;}

if /something/
{VAR = 500;}

delay (VAR);

You can think something of this.

NEVER use delay in a program. See blink without delay and this thread Demonstration code for several things at the same time - Project Guidance - Arduino Forum

Mark

holmes4:
NEVER use delay in a program. See blink without delay and this thread Demonstration code for several things at the same time - Project Guidance - Arduino Forum

Mark

It depend on what he wants. Delay is very simple but have limited functionality in the big project. So if you don't need to do few things at a time, delay is OK.

I cant really use a delay, because I need to do other things in the loop (such as read the problematic input, to make sure it sticks low). I apologize if I didn't clarify this before

I currently have this code working, but would need something that allowed more inputs without a bunch of variables for each:

long previousMillis = 0; 
long interval = 300;   
unsigned long currentMillis = 0;

void(loop);
{
if (no_pulse)
{
  //no_pulse = 0;
  currentMillis = millis();
}
  
  if((millis() - interval) > currentMillis) 
  {
   // Normal operation
   PORTD |= _BV(PORTD7);
  }
  else
  {
   // Changing input
   PORTD &= ~_BV(PORTD7); 
  }
}
if((millis() - interval) > currentMillis)

should be

if(millis() - prevMillis >= interval)

Normally currentMillis would be update with the value of millis() at the start of loop() so the code would be

if (currentMillis - prevMillis >= interval) {

...R