Creating a time stoppage

Hello, I am trying to have a fan and lights turn on for a specific amount of time. The fan is a CPU fan and the lights are small LEDs and I just want them to run for 8 seconds and then turn off. I need help on how to do that.

Under what conditions do they turn on?

I was worried for a moment there: thought you actually wanted to stop time!

You could just turn them on in setup(), delay(8000), then turn them off. And loop() would be empty.

That would answer your question as asked, but maybe tbereā€™s more to it than that?

Does, eg, the program need to do anything else during the on time. And as asked above, what makes them turn on?

I was worried for a moment there: thought you actually wanted to stop time!

Worried? I was hopeful! Next week's winning lottery numbers anyone?

Seriously DasDoctorisHere,
Work through the many examples in the IDE, on this web site and else where. Once you have done that you will most likly know the answer to your question. Also read 'how to use this forum - please read', that way you will know how to ask a question that's likely to get a helpful, friendly answer.

The demo Several Things at a Time illustrates the use of millis() to manage timing without blocking.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R

the typical thins is Blink Without Delay.

your switch goes on.

you note the time.
you check to see if 8.000 seconds pass
you stop time.

please give us some warning because if you are going to stop time, I would like to make sure my milk does not go bad.
I hate the smell of bad milk.

you should also work through the basic examples in the IDE.
detecting the edge of a switch is in the debounce example
and it introduces you to the use of millis() as you will need to use that for timing.