Advertisement
Guest User

Button press and hold do a b

a guest
Oct 15th, 2015
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. I'm using JChristensen's Button Library to debounce my buttons and provide extra functionality. I'm trying to use his press & hold function to do something if the button is pressed and held for greater than 2 seconds. If it is just pressed momentarily it should do something else. His example use switch cases, and I couldn't get it to work. Here is my example that currently doesn't work. https://github.com/JChristensen/Button
  2.  
  3. if (clearBtn.pressedFor(2000)) { // Enter settings menu
  4. Serial.println("Settings Menu");
  5. while (clearBtn.read()!=1) {
  6. //Stay in the settings menu until the button is pressed again to exit.
  7. variable1=5;
  8. } // End While
  9.  
  10. return; // Hopefully not proceed down to the next if statement } if (clearBtn.wasReleased() && !clearBtn.pressedFor(2000)) { varaible1=0; delay(50);
  11.  
  12. Can anyone help please? My serial output repeats "Entering menu over and over. Once I let go of the button variable1 always gets set to 0.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement