Button change

I am trying to track a momentary button change. Press once and it goes to on mode (1), press again and goes to off mode (0). If button is in on mode and no action has been taken (pressing momentary button to go back to off mode) it will default back to zero after a desired time (3 sec). I am new to writing code and I know this is basic stuff but I am having a hard time. Any Ideas?

Define a variable to hold the current mode.

Look in the StateChangeExample sketch to see how to read a switch input and detect when it is pressed and released. Use this approach to make the mode change when the switch is operated.

Look in the BlinkWithoutDelay example sketch to see how to make something happen after an interval. Use this approach to make the mode change after your 3 sec timeout has expired.

boolean latch = false;
unsigned long timer = 0;
byte LED_pin = 13;

void setup() {
.
.
.
}

void loop() {

//debounce code here

if(button == HIGH) {
latch = !latch;
timer = millis();

  if(latch == true && (millis() - timer < 3000) {
  digitalWrite(LED_pin, HIGH);
  }

  else {
  digitalWrite(LED_pin, LOW);
  }
 }
}

untested but if you fill in the rest, it should work.

Works with the exception mills()

I forgot to add a closing ) in the if statement.

Works with the exception mills()

???

Post your full code