Where is some good Bounce library (button debouncer) documen

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
DanPolka
 
Posts: 108
Joined: Tue Feb 18, 2014 5:31 am

Where is some good Bounce library (button debouncer) documen

Post by DanPolka »

I've been looking around, and can't seem to find any good documentation for the Bounce (debouncer) library.

I'm trying to find out how it can be used with multiple switches, and how to get it to report different kinds of keypresses.

I'm interested in, for instance, pressed-but-only-report-once (even if still held down, or for just brief single press, either one same report, a one-shot), & a report of held-down (past some length of time), & double-tap.

The point is to be able to use one switch to do many different things (through different kinds of key presses on it), while other switches do other things.

A listing of the various states & events the lib can perceive, and code examples for how to utilize the library to do each would be helpful, as would a tutorial or instructable.

User avatar
Franklin97355
 
Posts: 23938
Joined: Mon Apr 21, 2008 2:33 pm

Re: Where is some good Bounce library (button debouncer) doc

Post by Franklin97355 »

The .h and .cpp files in the library will give you the commands available. The first thing is to define your program as to what your inputs will be and what you want to happen when they occur.
The point is to be able to use one switch to do many different things (through different kinds of key presses on it), while other switches do other things.
is very confusing to program and will only get you in trouble. After you define your program take it one item at a time and set that to code then test.

DanPolka
 
Posts: 108
Joined: Tue Feb 18, 2014 5:31 am

Re: Where is some good Bounce library (button debouncer) doc

Post by DanPolka »

I'm sorry, I must have misunderstood what Bounce can do. I thought it could return info about different kinds of keypresses, not just debounce them.

When I look at the Bounce2.h file, what I find is:

Code: Select all

  // Attach to a pin (and also sets initial state)
  void attach(int pin);
	// Sets the debounce interval
  void interval(uint16_t interval_millis);
	// Updates the pin
	// Returns 1 if the state changed
	// Returns 0 if the state did not change
  bool update(); 
	// Returns the updated pin state
  bool read();
What I don't find is examples of how to use them (I'm not familiar with oops nor C), nor anything relating to getting returns for various kinds of keypresses.

That's why I'm hoping to be pointed towards a tutorial or instructable.

Franklin said:
The first thing is to define your program as to what your inputs will be and what you want to happen when they occur.
What I will want to happen will depend on, amongst other things, the nature of the keypress: a short quick keypress might intend to do one thing, a long hold do another, a double-tap do yet another. That's why I'm looking for something that will, in addition to debouncing the buttons, tell me what kind of pressing occured.

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Where is some good Bounce library (button debouncer) doc

Post by adafruit_support_bill »

What I will want to happen will depend on, amongst other things, the nature of the keypress: a short quick keypress might intend to do one thing, a long hold do another, a double-tap do yet another. That's why I'm looking for something that will, in addition to debouncing the buttons, tell me what kind of pressing occured.
Unless you can get away with continuously polling the associated pins, the best way to do what you want is with interrupts. Set up your buttons so that you can monitor them with pin-change interrupts. On each interrupt (rising edge or falling edge) you can check the state of the button(s). Find out what changed. And time stamp the event. From the record of key-down/key-up events you can characterize the different types of key presses.

http://www.geertlangereis.nl/Electronic ... ge_en.html

DanPolka
 
Posts: 108
Joined: Tue Feb 18, 2014 5:31 am

Re: Where is some good Bounce library (button debouncer) doc

Post by DanPolka »

@ Bill:
I had thought to use a continuous polling from a case statement in loop(), so that whenever a particular key was pressed, it would fall into the case for that key, and allow analysis of what kind of keypress occurred (from the return, see below) and what other conditions were relevant, since nothing would really be happening other than that polling until a key were pressed.

I'm assuming that a polling routine could return a 'coded' response to both any particular button pressed and the nature of the press, perhaps like this: any button amongst 9, plus some kind of keypress, return 1-9; a different kind of keypress, 11-19; yet another kind of keypress, 21-29. This would tell me what key and how it was pressed, to be sorted within my case statements.

I'd be a little concerned with using interrupts, because one of the results of a key press intends to be a Wave (spoken) output (probably not from WaveShield, as I run out of sram using its library), and the other result would be coded IR signal, both of which might be messed up if a keypress generated an interrupt??

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Where is some good Bounce library (button debouncer) doc

Post by adafruit_support_bill »

If you don't need the processor to do anything before or during the key-press, then polling is an option too. In either case, you need to track the key-down and key-up events and analyze the timing. Double-taps can be challenging. Typically, a user interface is designed such that a double-tap is an extension of a single-tap. That minimizes problems if the second tap comes too late to be recognized as linked to the first.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”