using arduino as a filter

hi,

I believe this is pretty simple, but I’m having a hard time, I’ve an input and an output, the arduino will only work as a filter so that when the input signal has been high for over a minute then the output will be set to high until the input signal is set to low, I’ve tried this with the bounce library but it was a complete fail it did all the opposite way.

can some one orient me to what should i be doing?

here is some pseudo code, since i don’t understand how to use timers, any comment appreciated.

THANKS!

const int out =2;
const int in = 5;

void setup(void)
{
  Serial.begin(9600);
  pinMode(in,INPUT);
  pinMode(out,OUTPUT);
}
void loop(){
        //start timmer
       while(digitalRead(in)){
              if(timer<60000){
               digitalWrite(out,HIGH)
              }
       }

}

can some one orient me to what should i be doing?

How would YOU do what needs to be done? You'd read the state of the pin. If the pin BECAME HIGH, you'd note what time that happened. Periodically (read that as "on every pass through loop()), you'd see if the pin was HIGH and now minus then (when the switch became HIGH) was greater than the necessary interval. If it was, you perform the necessary action.

So, which parts of this are not obvious how to translate into C?

hoe do you read the time??

does it have any problem on the counter being on for too long? the arduino will be on for a long time.

hoe do you read the time??

Relative (millis()) or absolute (get a RTC))?

found the millis function, i don't think i need an rtc, unless there is a problem reading millis after a very long period of time being on

unless there is a problem reading millis after a very long period of time being on

There will be. After about 300,000 years. If that's a problem.

Thanks Paul, worked liek a charm.

here it is

const int out =2;
const int in = 5;
unsigned long time =0;

void setup(void)
{
  Serial.begin(9600);
  pinMode(in,INPUT);
  pinMode(out,OUTPUT);
}
void loop(){
   if(digitalRead(in)){
     time = millis();
     while(digitalRead(in)){
       if(millis()-time>6000){
         digitalWrite(out,HIGH);
       }
     }
     digitalWrite(out,LOW);
   }
}

There will be. After about 300,000 years. If that's a problem.

Paul: I plan on living forever. So far, so good...

I plan on living forever.

Me too. Today I achieved a personal best as to how many days I have lived.

just as a fact, i see that millis return an unsigned long which is 4,294,967,295 and converting it to years its .13 years, where dod 300000 years came from?

i see that millis return an unsigned long which is 4,294,967,295 and converting it to years its .13 years

Time to put new batteries in the calculator

I plan on living forever.

Or die in the attempt.