Problem with the Boune library

Hello, I just start in Arduino, and I’m testing the library Bounce2 with my card Arduino DUE.
I used an example provided with the library: Bounce.
But the compiler always shows me the error lines and I have not changed anything in the code:

userpicture
Buy
Download
Products
Learning
Forum
Support
Blog

LOG IN
SIGN UP

Arduino Forum

International
Français
problème de compilation avec la bibliothèque Bounce2

Print
Go Down
Pages: [1]
Topic: problème de compilation avec la bibliothèque Bounce2 (Read 18 times) previous topic - next topic
matrix4

avatar_matrix4
*
Newbie
Posts: 5
[add Karma]
[add Karma]

problème de compilation avec la bibliothèque Bounce2
Today at 02:48 pm
Bonjour, je viens de débuter en Arduino, et je suis en train de tester la bibliothèque Bounce2 avec ma carte ARDUINO DUE.
J’ai utilisé un exemple fourni avec la bibliothèque : Bounce.
Mais le compilateur m’affiche toujours ces lignes d’erreurs et j’ai rien changé dans le code:

Arduino : 1.5.8 (Windows 7), Carte : “Arduino Due (Programming Port)”

C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘void Bounce::attach(int)’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:27:36: error: ‘_BV’ was not declared in this scope
state = _BV(DEBOUNCED_STATE) | _BV(UNSTABLE_STATE);
^
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘bool Bounce::update()’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:58:32: error: ‘_BV’ was not declared in this scope
state &= ~_BV(STATE_CHANGED);
^
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘bool Bounce::read()’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:81:39: error: ‘_BV’ was not declared in this scope
return state & _BV(DEBOUNCED_STATE);
^
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘bool Bounce::rose()’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:86:41: error: ‘_BV’ was not declared in this scope
return ( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
^
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘bool Bounce::fell()’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:91:42: error: ‘_BV’ was not declared in this scope
return !( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));

############################################################
############################################################
For scketch the BOUNCE is:

Arduino

userpicture
Buy
Download
Products
Learning
Forum
Support
Blog

LOG IN
SIGN UP

Arduino Forum

International
Français
problème de compilation avec la bibliothèque Bounce2

Print
Go Down
Pages: [1]
Topic: problème de compilation avec la bibliothèque Bounce2 (Read 18 times) previous topic - next topic
matrix4

avatar_matrix4
*
Newbie
Posts: 5
[add Karma]
[add Karma]

problème de compilation avec la bibliothèque Bounce2
Today at 02:48 pm
Bonjour, je viens de débuter en Arduino, et je suis en train de tester la bibliothèque Bounce2 avec ma carte ARDUINO DUE.
J’ai utilisé un exemple fourni avec la bibliothèque : Bounce.
Mais le compilateur m’affiche toujours ces lignes d’erreurs et j’ai rien changé dans le code:

Arduino : 1.5.8 (Windows 7), Carte : “Arduino Due (Programming Port)”

C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘void Bounce::attach(int)’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:27:36: error: ‘_BV’ was not declared in this scope
state = _BV(DEBOUNCED_STATE) | _BV(UNSTABLE_STATE);
^
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘bool Bounce::update()’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:58:32: error: ‘_BV’ was not declared in this scope
state &= ~_BV(STATE_CHANGED);
^
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘bool Bounce::read()’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:81:39: error: ‘_BV’ was not declared in this scope
return state & _BV(DEBOUNCED_STATE);
^
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘bool Bounce::rose()’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:86:41: error: ‘_BV’ was not declared in this scope
return ( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
^
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp: In member function ‘bool Bounce::fell()’:
C:\Users\MATRIX\Documents\Arduino\libraries\Bounce2-master\Bounce2.cpp:91:42: error: ‘_BV’ was not declared in this scope
return !( state & _BV(DEBOUNCED_STATE) ) && ( state & _BV(STATE_CHANGED));
^
Erreur lors de la compilation.

Ce rapport contiendrait plus d’informations si l’option
“Montrer les informations de sortie pendant la compilation”
était activée dans Fichier > Préférences.
matrix4

avatar_matrix4
*
Newbie
Posts: 5
[add Karma]
[add Karma]

Re: problème de compilation avec la bibliothèque Bounce2
#1
Today at 02:49 pm
Pour le scketch du BOUNCE est :
#include <Bounce2.h>

#define BUTTON_PIN 8
#define LED_PIN 13

// Instantiate a Bounce object
Bounce debouncer = Bounce();

void setup() {

// Setup the button with an internal pull-up :
pinMode(BUTTON_PIN,INPUT_PULLUP);

// After setting up the button, setup the Bounce instance :
debouncer.attach(BUTTON_PIN);
debouncer.interval(5); // interval in ms

//Setup the LED :
pinMode(LED_PIN,OUTPUT);

}

void loop() {
// Update the Bounce instance :
debouncer.update();

// Get the updated value :
int value = debouncer.read();

// Turn on or off the LED as determined by the state :
if ( value == LOW ) {
digitalWrite(LED_PIN, HIGH );
}
else {
digitalWrite(LED_PIN, LOW );
}

}

thank you for your help

I'm testing the library Bounce2 with my card Arduino DUE.

That library is not written for the DUE.

thank you for your response,
how I can solve the problem rebound?

It is extremely unlikely that you need the bounce library at all. Look at the simple way bounce is dealt with in several things at a time and how it requires no special treatment in planning and implementing a program.

...R

matrix4:
thank you for your response,
how I can solve the problem rebound?

I don’t know exactly what you want to do, but here is some demo code you can use for reading multiple buttons in your program.

#define INPUTMODE INPUT_PULLUP    // INPUT or INPUT_PULLUP
#define BOUNCETIME 5              // bouncing time in milliseconds
byte buttonPins[]={2, 3, 4, 5, 6};// pin numbers of all buttons
#define NUMBUTTONS sizeof(buttonPins) // number of buttons (automatically calculated)
byte buttonState[NUMBUTTONS];  // array holds the actual HIGH/LOW states
byte buttonChange[NUMBUTTONS]; // array holds the state changes when button is pressed or released
enum{UNCHANGED,BUTTONUP,BUTTONDOWN};

void input(){
// read the input state and state changes of all buttons
  static unsigned long lastButtonTime; // time stamp for remembering the time when the button states were last read
  memset(buttonChange,0,sizeof(buttonChange)); // reset all old state changes
  if (millis()-lastButtonTime<BOUNCETIME) return;  // within bounce time: leave the function
  lastButtonTime=millis(); // remember the current time
  for (int i=0;i<NUMBUTTONS;i++) 
  {
    byte curState=digitalRead(buttonPins[i]);        // current button state
    if (INPUTMODE==INPUT_PULLUP) curState=!curState; // logic is inverted with INPUT_PULLUP
    if (curState!=buttonState[i])                    // state change detected
    {
      if (curState==HIGH) buttonChange[i]=BUTTONDOWN;
      else buttonChange[i]=BUTTONUP;
    }
    buttonState[i]=curState;  // save the current button state
  }
}


void output(){
// send a message to Serial if a button state (pressed/released) has changed
// button pressed: Send button pin number with minus sign
// button released: Send button pin number
  byte action;
  for (int i=0;i<NUMBUTTONS;i++)
  {
    switch (buttonChange[i])  
    {
      case BUTTONUP: Serial.println(buttonPins[i]);break;
      case BUTTONDOWN: Serial.println(-buttonPins[i]);break;
    }
  }
}


void setup() {
  Serial.begin(9600); // initialize Serial at 9600 baud
  // then initialize all buttons
  for (int i=0;i<NUMBUTTONS;i++) pinMode(buttonPins[i],INPUTMODE);
}

void loop() {
  input();
  // processing(); // if you need any processing, write a function for it!  
  output();
}

The demo sketch consists of an “input()” function that reads all the button-pins and an “output()” function that shows any changes of a button state in the Serial monitor.

Cabling your circuit:
When you connect just the buttons to the Arduino (no pull-resistors) set INPUTMODE to INPUT_PULLUP. And when you use external pull-down resistors in your circuit, set INPUTMODE to INPUT. The sketch will work with both settings.

If your program needs any processing, write a function for it!
Or if your program needs any other output, change the “output()” function!

Think you all for your help :grin: