Button Press timing/relay

Hi Guys,

Thanks for your help so far! I wasn't sure where to post this question but since the solution may be either coding or hardware, I thought this would be a good place...

Is it possible to make a single button press last for a desired amount of time? For example, I'd like a single on/off button to last for 1 second within the code. This would act like a relay in a way where activating the relay would cause it to turn on and off for given time.

For example, a simple led on/off could be controlled using the button: press button, led turns on, let go of button, led turns off. You could of course tell the led to stay on for 1 second when the button is pressed once but for what I'm trying to achieve, I think I need the 'led' to 'think' the button has been held down for longer.

So I could have something like:

if (button == HIGH);
1000ms = 'buttonHeld'

Then in the void loop,

if (buttonHeld == HIGH)


Does this make any sense? Obviously this language is wrong but this is what I'm not sure about

Many thanks in advance,


Sorry, I meant to post this to another forum!