10 Second Timer

Hi Shannon. You seen you are very confident with the programs. I have just started. may be you can help me.

I have a program and works fine.
Function
1 press button . Result Led green ON
2 press same button Result Leds green & yellow OFF
3 Press same button Result Led yellow ON
4 Press same Button Result Leds green & yellow OFF

Then just loop in this manner

Now would like to make a 10 second timer on each Led so when in ON state they will switch OFF after 10 second. I tried with millis but do not know the procedure .
The circuit is simple only 2 leds on pins 6 & 7 and push button on pin on pin 5 with a 10K resistor to earth for debounce

See program underneath

//----------------------------------------------------------------------
// Sunday 02 06 2018
// First attempt to 2 WAY and OFF Latch Switch
// Need to add a 10 second timer on each led

#define button 5
#define greenLED 6
#define yellowLED 7

int state = 0;
int old = 0;
int buttonPoll = 0;

void setup(){
pinMode(button,INPUT);
pinMode(greenLED,OUTPUT);
pinMode(yellowLED,OUTPUT);

digitalWrite (greenLED, LOW);
digitalWrite (yellowLED, LOW);

}

void loop()
{
buttonPoll = digitalRead (button);
if ( buttonPoll == 1 ) {
delay (50) ;
buttonPoll = digitalRead (button);
if ( buttonPoll == 0 )
{
state = old + 1;
}}
else {
delay (100);
}

switch (state) {
case 1:
digitalWrite (greenLED, HIGH);
digitalWrite (yellowLED, LOW);
old = state;
break;

case 2:
digitalWrite (greenLED, LOW);
digitalWrite (yellowLED, LOW);
old = state;
break;

case 3:
digitalWrite (greenLED, LOW);
digitalWrite (yellowLED, HIGH);
old = state;
break;
default:
digitalWrite (greenLED, LOW);
digitalWrite (yellowLED, LOW);
old = 0;
break;
}
}
//----------------------------------------------------------------------------------------------

I would appreciate any help
Best regards
Charles email: chbonnici@gmail.com

@mbe200, you have asked your question in a 3-years dead Thread.

I am suggesting to the Moderator to move your question to its own Thread.

Have a look at how millis() is used to manage timing in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R

PS ... To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Thread split.