Using a button to toggle an LED ON/OFF
I tested your sketch and it works. I simplified it; it's the same logic, but in a more concise way:

void loop()
{
    reading = digitalRead(buttonPin);

    // if the input just went from LOW and HIGH and we've waited long enough
    // to ignore any noise on the circuit, toggle the output pin and remember
    // the time
    if(reading == HIGH  &amp;&amp; previous == LOW &amp;&amp; millis() - time &gt; debounce) {
        state = !state;
        time = millis();
    }

    digitalWrite(ledPin, state);
    Serial.println(reading);
    previous = reading;
}


setup is still the same.