Button Combinations Debounced with jm_debounce?
coryco2
Posts: 107
I am trying to debounce multi-button combinations with jm_debounce from the Object Exchange http://obex.parallax.com/objects/489/
It seems to work fine for OR-ing multiple buttons like this:
but not AND-ing...which is what I want to use it for:
Can this be made to work for debouncing when trying to detect only when two or more button are pressed in combination?
It seems to work fine for OR-ing multiple buttons like this:
con BTN_A = 0001 << 18 'pin 18 BTN_B = 0010 << 18 'pin 19 BTN_C = 0100 << 18 'pin 20 BTN_D = 1000 << 18 'pin 21 BTN_E = 0000 << 18 'pin 22 BTN_F = 0000 << 18 'pin 23 BTN_MASK = BTN_A | BTN_B | BTN_C | BTN_D | BTN_E | BTN_F ACT_HI = 1 ACT_LO = 0 obj btns : "jm_debounce" PUB Main | b btns.init(BTN_MASK, 25, ACT_HI) repeat IF b := btns.getbits(BTN_A | BTN_B) SomeMethod ELSE SomeOtherMethod
but not AND-ing...which is what I want to use it for:
PUB Main | b btns.init(BTN_MASK, 25, ACT_HI) repeat IF b := btns.getbits(BTN_A & BTN_B) SomeMethod ELSE SomeOtherMethod
Can this be made to work for debouncing when trying to detect only when two or more button are pressed in combination?
Comments
I think you may be taking the term OR too literally here. In the above snippet the single-bit masks are ORed together to form a multi-bit mask; in this case, both bits must be active for the expression to evaluate as true. In this case the code is only looking for BTN_A and BTN_B to be active at the same time.