Go Down

Topic: Bounce (and Bounce 2) Library Official Question Forum (Read 15166 times) previous topic - next topic

tyrayb

Thanks for the Bounce library.

I am working with a Due board and discovered that the _BV macro used for this library is not defined in the Due's libraries.

It's a simple macro, so I just added it to the Bounce2.cpp:

#ifndef _BV
#define _BV(x) (1 << (x))
#endif

There is probably a more "correct" way to check if the target board is a Due, but this worked just fine.

-Tyler

docsteve

Hello

I'm trying to use your Bounce library. I have downloaded "Bounce2-master.zip" and unzipped it as instructed.

I read in your INSTALL.txt file "Put the "Bounce2" folder in your Arduino or Wiring "libraries" folder. "

I've searched my computer and I am unable to find the "Bounce2" folder.

The closest I can find is a folder called "Bounce2-master".

Is your reference to the "Bounce2" folder an error and I should use the "Bounce2-master" folder instead?

I didn't want to use the "Bounce2-master" folder in case it screwed up my computer.

Regards
Steve

Chris72622

#32
Mar 07, 2015, 01:52 pm Last Edit: Mar 07, 2015, 04:21 pm by Chris72622
Rename it Bounce2.

Greetz Chris
Suche PoE Modul für Ethernet Shield

docsteve

Hi Chris

My Windows 7 Home premium won't let me rename the folder "Bounce2-master" so is your reference to the "Bounce2" folder an error and I should use the "Bounce2-master" folder instead?

Cheers
Steve

Chris72622

Suche PoE Modul für Ethernet Shield

fusionstream

This is sort of a C/C++ question.

Would it be possible to debounce.attach(aFunc, aFuncArg) and do it by reference(?) ?

I'm using the adafruit MCP23017 library and it doesn't have inbuilt debounce.

This way, the debounce2 lib could call the function on update() without having to be aware of the function or class it is in. Then a simple bool variable will tell update() whether it is checking a pin or checking the return of a function.

fusionstream

oooo... I guess I should read my emails before I post.

So coincidental! (The merge request isn't mine btw)

https://github.com/thomasfredericks/Bounce2/pull/14

MitchSF

Hi All,

Bounce2 will not compile on the Zero. Below are the errors. Please fix if at all possible.  The same program works on the Micro.

Thanks.


C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp: In member function 'void Bounce::init(bool)':
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp:23:36: error: '_BV' was not declared in this scope
         state = _BV(DEBOUNCED_STATE) | _BV(UNSTABLE_STATE);
                                    ^
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp: In member function 'bool Bounce::update(bool)':
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp:57:32: error: '_BV' was not declared in this scope
     state &= ~_BV(STATE_CHANGED);
                                ^
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp: In member function 'bool Bounce::read()':
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp:85:39: error: '_BV' was not declared in this scope
     return state & _BV(DEBOUNCED_STATE);
                                       ^
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp: In member function 'bool Bounce::rose()':
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp:90:41: error: '_BV' was not declared in this scope
     return ( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
                                         ^
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp: In member function 'bool Bounce::fell()':
C:\Users\Mitchell\SkyDrive\Arduino\Arduino\libraries\Bounce2\Bounce2.cpp:95:42: error: '_BV' was not declared in this scope
     return !( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
                                          ^
Error compiling.

danielsl

Looks like all features i need
But
I got multiple errors on compiling
<code>

In file included from spectro14.ino:2:0:
C:\Program Files (x86)\Arduino\libraries\Bounce_switch/switch.h:16:15: error: expected ')' before '_pin'
   Switch(byte _pin, byte PinMode=INPUT_PULLUP, bool polarity=LOW, int debounceDelay=50, int longPressDelay=400, int doubleClickDelay=250);
               ^
In file included from spectro14.ino:2:0:
C:\Program Files (x86)\Arduino\libraries\Bounce_switch/switch.h:28:9: error: 'byte' does not name a type
   const byte pin;
         ^
spectro14:10: error: no matching function for call to 'Switch::Switch(const byte&)'
spectro14.ino:10:39: note: candidates are:
In file included from spectro14.ino:2:0:
C:\Program Files (x86)\Arduino\libraries\Bounce_switch/switch.h:13:7: note: Switch::Switch()
 class Switch
       ^
C:\Program Files (x86)\Arduino\libraries\Bounce_switch/switch.h:13:7: note:   candidate expects 0 arguments, 1 provided
C:\Program Files (x86)\Arduino\libraries\Bounce_switch/switch.h:13:7: note: Switch::Switch(const Switch&)
C:\Program Files (x86)\Arduino\libraries\Bounce_switch/switch.h:13:7: note:   no known conversion for argument 1 from 'const byte {aka const unsigned char}' to 'const Switch&'
spectro14:11: error: no matching function for call to 'Switch::Switch(const byte&)'
spectro14.ino:11:45: note: candidates are:
In file included from spectro14.ino:2:0:
C:\Program Files (x86)\Arduino\libraries\Bounce_switch/switch.h:13:7: note: Switch::Switch()
 class Switch
       ^

</code>

m4rc10w

Hello everyone

It can use this library (Bounce 2) to filter a button connected to an ANALOG input of Arduino (by reading that entry in digital form, of course)? If yes, it can be very useful on boards that have limited amount of digital inputs (such as Uno and Leonardo) compared to the Arduino Mega.

Sorry for my bad English, translated with Google Translate :)

Doc_Arduino

Hi Thomas Fredericks,

can you update your library, please?

The IDE 1.6.7. show every example

Quote
... \libraries\Bounce2\Bounce2.cpp: In member function 'void Bounce::attach(int)':

... \libraries\Bounce2\Bounce2.cpp:24:10: warning: unused variable 'read' [-Wunused-variable]

     bool read = digitalRead(pin);

          ^
Quote
void Bounce::attach(int pin) {
    this->pin = pin;
    bool read = digitalRead(pin);
    state = 0;
    if (digitalRead(pin)) {
        state = _BV(DEBOUNCED_STATE) | _BV(UNSTABLE_STATE);
    }
#ifdef BOUNCE_LOCK_OUT
    previous_millis = 0;
#else
    previous_millis = millis();
#endif
}
or can I delete this command ?

thanks.
Tschau
Doc Arduino '\0'

Messschieber auslesen: http://forum.arduino.cc/index.php?topic=273445
EA-DOGM Display - Demos: http://forum.arduino.cc/index.php?topic=378279

Mozz164

Hi, I have already typed this once and lost it, my internet decided to disconnect right before i pressed post.  >:(    so here goes again...

I am currently working on a reaction testing machine based on the Teensy 3.1

Basically, is consists of 16 LED Back-lit buttons on a 4x4 grid. Each of the buttons will light up randomly and the player has to press the button as quick as possible. The reaction time will be read out on a multi-digit 7-segment display or an 8x8 Bi-colour matrix.

so, there are 16 inputs (buttons) and 16 outputs (LED Backlights).  --> More than teensy can handle (plus I need another few for various other things)...so, I have decided to use two '4-to-16 Analogue Multiplexers' which are bi-directional. I can control the LEDs on their own, no problem.

The Problems start when I try to progressively poll the switches in turn until I have found one that is pressed. I am basically counting up from 0-15 in binary and outputting this to the four address pins of the multiplexer.

I am then reading the signal pin, once per loop iteration, to see if a button has been pressed. I can sense that buttons have been pressed, that works fine. The problems come when i am trying to store the actual button that was pressed, so that i can compare that against the random number that was generated.

I am forced to simply save the exact channel that the multiplexer was reading right at the moment when the muxDebounce.read() function flagged that a button had been pressed. But when i press the button multiple times (at probably once every 2-3 seconds), most of the time the value is correct, but sometimes it gives a different value. (usually 'value + 1')....its like the program is running too fast and causing itself to skip over the check to see if the button is currently LOW.

I have tried various different ways of using the Bounce library, and its frustrating me that i can seem to be able to get a consistent result.

Please if you have a couple of minutes spare, could you take a quick look over the code to see if I'm missing something obvious. Hope its something stupid.

Anyway i have included the source code (.ino) and a screenshot of the Serial Monitor showing the intermittent results. Any help at all is appreciated

Thanks very much!

dillonradio

If I want to use the bounce2.h library inside another library, where should I be declaring the setup code? Should some go in the class constructor or inside the begin() code to go in setup?


cesart050892

hi I added library Bounce2, IDE arduino dont recognize.????

why???

dstacer

Would it be possible to pass the initial state=x in the attach() parameter list?  The code currently defaults to setting state=0;

In my situation, the program is reading the value of a pin that is under the control of a USB to serial adapter. Sometimes on power-up the USB adapter is slow in getting to its true state of 1 and the program has already started.

I have a switch that will pull that pin to GND indicating a condition.

On program startup if you make a read() call before enough update() have been called, the read is really just returning the default state and not a de-bounced value.

I want to know when the switch pulls down the pin for 5 seconds. This is only a startup issue. When the program is running for 5+ seconds read() will return the accurate value of the pin because the USB adapter has taken the pin high and enough update() have been called to set state <> 0.

I've worked around this by not calling the read() until the normal de-bounce time has passed but it would be nice to have the ability to set state to something other than 0.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy