debounce and blinking using millis()

const int button = 2;
const int led = 13;

int buttonState;
int preButtonState = LOW;
int ledState = LOW;
int interval = 1000;

unsigned long debounceTime = 50;
unsigned long preDebounceTime = 0;
unsigned long preMillis = 0;

void setup() {
  pinMode(button, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(115200);
  digitalWrite(led, ledState);
}

void loop() {
  int reading = digitalRead(button);
  if (reading != preButtonState) {
    preDebounceTime = millis();
  }
  if ((millis() - preDebounceTime) > debounceTime) {
    if (reading != buttonState) {
      buttonState = reading;
      if (buttonState == HIGH) {
        if ((millis() - preMillis) > interval) {
          ledState = !ledState;
        }
      } else {
        ledState = LOW;
      }
    }
  }
  digitalWrite(led, ledState);
  preButtonState = reading;
  Serial.println(ledState);
}

I'm trying to practice coding by combining the basic codes that I've learned.
The code I'm trying to built is to have a toggle button with blinking led.
both are using millis() instead of delay.
But the problem is that the toggle switch nologner "latch" on. this is because the "buttonState" is nolonger high the moment I let it go.
I'm a very slow learner, please help me out.

It's better for you to describe what you want to do (ie. describe your objective), rather than say something no longer latches. Most readers here aren't clairvoyant/mind readers.

You should at least describe to people what your code is supposed to do (or meant to do), and then indicate what actually works, and indicate what is not working.

Southpark:
It's better for you to describe what you want to do (ie. describe your objective), rather than say something no longer latches. Most readers here aren't clairvoyant/mind readers.

You should at least describe to people what your code is supposed to do (or meant to do), and then indicate what actually works, and indicate what is not working.

I'm trying to combine both the examples from arduino ide (debounce and blinking without delay examples)

  1. no led lights up when no button is press.
  2. led lights start to blink when button is press.
  3. no delay function is used, use millis() instead of delay()

If the LEDs go on flashing after the pushbutton, you don't need any debounce. Just any detection of pushbutton will do. Unless your requirements are more than what you mentioned.

The loop() runs continuously, so you need some way to know what state you are currently in, and then you can read this state and action accordingly.

What I would do is use a boolean variable, which would tell me if the led should be flashing or turned off. When the button is pressed you can invert this boolean variable. Then you can check this variable and flash the led if it is true, or turn it off if it is false.