Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False trigger on button Resolved #2

Open
hicmikrolab opened this issue Dec 16, 2024 · 0 comments
Open

False trigger on button Resolved #2

hicmikrolab opened this issue Dec 16, 2024 · 0 comments

Comments

@hicmikrolab
Copy link

Thank you for the wonderful work here, However I observed multiple false trigger in the code, so i attached a de-bounce code to make it work smoothly.

void loop() {
  static bool lastButtonState = LOW; // Track the previous button state
  static unsigned long lastDebounceTime = 0; 
  const unsigned long debounceDelay = 50; // 50ms debounce time

  int currentButtonState = digitalRead(triggerButton);

  // Check for state change and debounce
  if (currentButtonState != lastButtonState) {
    lastDebounceTime = millis(); // Reset debounce timer
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // If the button state is stable and pressed
    if (currentButtonState == HIGH) { // Button pressed (HIGH with pull-down)
      int status = sendPhoto();
      if (status == -1) {
        displayText("Image Capture Failed");
      } else if (status == -2) {
        displayText("Server Connection Failed");
      }
      delay(500); // Additional delay for user feedback (optional)
    }
  }

  lastButtonState = currentButtonState; // Update the button state

}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant