Latching a Momentary Button to last pressed state

My objective is to switch a LED either continuously ON or OFF with single momentary button presses. I have been searching the forum for examples to latch the LED into the last button state. I also added debounce from the debounce.2 library but cannot get the LED to stay lit. I have the button input pulled high and the other end of the button grounded. I have added serial.print statements liberally to verify that the button input and led outputs are otherwise wired and working fine. With the code below the LED stays lit (blinking) while I hold the button down. It does not keep the last LED state.

Here is my code and any advice appreciated:

#include <Bounce2.h>    

#define BUTTON1             4  
#define LED1                7  

byte  value1 = 1;
boolean LEDstate = false;

// Instantiate a Bounce object for each button
Bounce Mbutton1 = Bounce(); 

void setup() {
  // Setup the button
  // Activate internal pull-up
  digitalWrite(BUTTON1,INPUT_PULLUP); // goes low when pressed
  // assign button to pin
  //Setup the LED

void loop() {
  //Update button1
  value1 =; // if high then button NOT pressed
  if (value1 == 0)  //button pressed
    Serial.println("Button pressed");
    switch (LEDstate){
      case 0:
        LEDstate = HIGH;
      case 1:
        LEDstate = LOW;

As currently written the program changes LEDstate when the button [u]IS[/u] pressed rather than when it [u]BECOMES[/u] pressed so it will change very rapidly. There is a StateChangeDetection example in the IDE that will show you how to detect the change from not pressed to pressed.

here's some rudimentary debounce code and a state toggle on press and release of a push button. You can add more code to the ToggleState function, which gets called every time the button is pushed, and the state variable will give you an indication of the current state (0 or 1)

//Connect a normally open switch between 3 and ground
#define BUTTONPIN 3
#define LEDPIN 13

unsigned long buttonDebounce = 0;
byte state = 0;

void setup() {
  pinMode(LEDPIN, OUTPUT);
  digitalWrite(BUTTONPIN, HIGH); // enable internal pullup

void ToggleState() {
  state = state ^ 1; //XOR 1 toggles LSB, effectively jumping between 0 and 1  
  digitalWrite(LEDPIN, state);

void loop() {
  if (digitalRead(BUTTONPIN) == 0 && buttonDebounce == 0) {
    //button pushed, get current time for debouncing
    buttonDebounce = millis();

  if (digitalRead(BUTTONPIN) == 1) {
    if ((buttonDebounce != 0) && (millis() - buttonDebounce > 20)) {
    buttonDebounce = 0;