Go Down

Topic: Trying to solve debounce problem (Read 879 times) previous topic - next topic

JoshSG

Hi,
      // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == LOW) {     
    // turn LED on:   
    digitalWrite(ledPin, HIGH); 
     // print out the state of the button:
         if (switch0 == 0){
            Serial.print("ON ");
            Serial.println(buttonState);
            switch0=1; ///<<--------------THIS ONE WORKS FOR ME AND NEVER MISSED HOW LONG/SHORT   THE BUTTON HAS BEEN PRESSED
            }
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    if (switch0==1){
           Serial.print("OFF ");
           Serial.println(buttonState);
           switch0=0;    ///<<--------------THIS ONE WORKS FOR ME AND NEVER MISSED HOW LONG/SHORT   THE BUTTON HAS BEEN PRESSED   
    }

HazardsMind

@JoshSG
Thats has nothing to do with debounce, that is a latch. And it still wont work correctly with out a proper debounce code.
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

holmes4

@joshSG,

Layout code using auto format before postimg and always post code in code tags!.

Mark

JoshSG

Hi,
      I tried the debounce in the example and it does not work for my application, any name will do, debounce, latch, lock as long as it has met the objective, just want to share, it is for all who those who wants to try. 8)

Thanks,

Josh

HazardsMind


Hi,
     I tried the debounce in the example and it does not work for my application, any name will do, debounce, latch, lock as long as it has met the objective, just want to share, it is for all who those who wants to try. 8)

Thanks,

Josh



Actually name does matter, because a latch and a debounced button/switch are two different things.
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Go Up