Timing

Hello, good day, hope we are great?
How do I use millis to time an input which is either HIGH or LOW, such that, if the input stays HIGH or LOW for more than 8 seconds, there should be an alarm.

Thanks in advance.
Ceejay.

(deleted)

How? Almost exactly as you stated. Only one piece of information is missing, you need to record the start time of the event

If triggered, store millis() value and trigger_value when triggered

if millis()-trigger_time > 8000 and digitalRead(pin) <> trigger_value then alarm

Please, can you help me with a sketch for that?

Ceejay90:
Please, can you help me with a sketch for that?

That request goes in Gigs and Collaborations. Helping is free, working costs money.

Lol, please, I'm new at with Arduino, and that setup is my first program.

Thanks

Lol, please, I'm new at with Arduino, and that setup is my first program.

Then start by studying the blink without delay example, so you will understand how to use the millis() timer.

Or this tutorial, the first post in the Programming section.

How? Almost exactly as you stated. Only one piece of information is missing, you need to record the start time of the event

If triggered, store millis() value and trigger_value when triggered

Or, please can you explain more, I don't seem to understand

It is difficult to give specific answers to generic questions.

When the input state changes (digitalRead(pinX) <> last_state), record the time it changed (trigger_time = millis() ) and the current state (last_state = digitalRead(pinX) )

if millis() - trigger_time > 8000 and digitalRead(pinX) <> last_state then alarm

But this works for any change on pinX (high to low or low to high). This is likely not want you want. As mentioned, generic question = generic answer. Unlike many others, I don’t mind generic questions, but it is up to the poster to understand how to use the generic answer given.

Smiles

Thanks a lot, this would help greatly