having trouble installing and the bounce Library

Hi all,
Im a newbie to the Arduino and writing code, i’ve done a few simple programs controlling LEDs, they seem to have gone well, but now I’m trying to do something a bit more interesting.
So I’m going about making a buzz off wire and loop game with LED’s that light up and stay on each time the wires make contact.
My problem is that i want download and install the bounce library to eliminate the bounce generated.
However i think I’ve put the bounce folder in the wrong place, do i put it in the arduino sketch folder? (thats where i have it now)
There is nowhere I can import the library in the menu bar!!

I have
#include <Bounce.h>”
At the top of my sketch and get a message saying
20:error: Bounce.h:no Such file or directory"

any help would be much appreciated.

However i think I've put the bounce folder in the wrong place,

You did. In the folder where you installed the IDE, there is a folder called hardware (at least on Windows), containing a folder called libraries. That is where you put the library folder.

thanks for the reply but I'm using a mac, and there's no hardware folder in the applications folder where the arduino IDE is installed. I put have now put the bounce folder in user/library/arduino but this is having the same error message as before. very confused!! :-?

I think that you need to create a folder on the Mac. Which folder, and where it goes, I do not know. A search of the forum for library issues should yield some results.

On general principles, you should probably sort out the libraries folder issue... but in the meantime, why not just write your own code to take care of the bounce problem? Should be easy enough, and you get just the de-bounce stuff you need, and you end up understanding bounce issues better.

I suspect all that you need is a delay after a "user touched the wire" event before the program starts to look for another "touched" event.

Fun idea!

I assume that the Arduino is also giving the user either a "time TAKEN to complete task" output or a time LIMIT to complete task, or similar?

This would be a great programming class challenge!

thanks for the reply's, I found out how to get the bounce Library in there, its right click on arduino in applications folder, show package contents, then its contents/resources/java/hardware/libraries this is thanks to another poster somewhere else on this form however he did say to put them in documents/arduino and create a library folder here however that didn't work for me... any way working now.

Thanks tkbyd for your idea to right some code to take care of the bounce issues, I did try that however i cant seem to control the delay time to great effect. I would like to put a timer on it but, ill see how I go with the led's lighting up first, then introduce a buzzer, then ill try the timer, controlling an LCD.... I don't think I'm ready for that just yet.

one step at a time... a lot of this code is just going straight over my head.... but I think I'm getting there.

thanks for the help

You said...

one step at a time

.. which is EXACTLY right. With that plan, you should do well.

HI All... things seem me to be getting a bit tricky.... for me any way... (pretty much first time trying to right a program....) Quick Up Date on what i'm trying to do

Its a buzz off wire contact game, I have 3 LED's and a buzzer each time the handle wire makes contact to the wire game, the buzzer sounds for 1 second and 1 LED comes on and stays on, each time the wires make contact the buzzer will sound and another LED lights up and stays on.

So I seen to be having a bit of trouble controlling the "bounce" or delay for the contact of the wires, because I'm physically holding two wires together to make contact. you do get a lot of "bounce" and the three LED's i've set up can sometimes switch on in what should only be one touch. I also seem to be having trouble with the buzzer... after i introduced that code It all went pare shaped.... I will admit most of this code is copy and pasted from other examples and tweaked a little any nudge in the right direction is much appreciated

I need to be able to delay the contact time or pause the counting some how i think.

 /*
 Its a buzz off wire contact game, 
I have 3 LED's and a buzzer
each time the handle wire makes contact to the wire game,
the buzzer sounds for 1 second and 1 LED comes on and stays on,
each time the wires make contact the buzzer will sound and another LED lights up and stays on. 
 */


 // this constant won't change:
 const int  buttonPin = 2;    // the pin that the pushbutton is attached to
 const int led1Pin = 11;       // the pin that the LED is attached to
 const int led2Pin = 12; 
 const int led3Pin = 13;
const int buzzpin = 9; 
 // Variables will change:
 int buttonPushCounter = 0;   // counter for the number of button presses
 int buttonState = 0;         // current state of the button
 int lastButtonState = 0;     // previous state of the button
  int i = 0;
  
 // the following variables are long's because the time, measured in miliseconds,
 // will quickly become a bigger number than can be stored in an int.
 long lastDebounceTime = 0;  // the last time the output pin was toggled
 long debounceDelay = 5;    // the debounce time; increase if the output flickers

 void setup() {
   // initialize the button pin as a input:
   pinMode(buttonPin, INPUT);
   // initialize the LED pin as an output:
   pinMode(led1Pin, OUTPUT);
   pinMode(led2Pin, OUTPUT);
   pinMode(led3Pin, OUTPUT);
   pinMode(buzzpin, OUTPUT);
   // initialize serial communication:
   Serial.begin(9600);
 }
 void loop() {
   // read the pushbutton input pin:
   buttonState = digitalRead(buttonPin);
   // compare the buttonState to its previous state
   if (buttonState != lastButtonState) {
     lastDebounceTime = millis();
     // if the state has changed, increment the counter
     if (buttonState == HIGH) {
       // if the current state is HIGH then the button
       // wend from off to on:
       buttonPushCounter++;
       Serial.println("on");
       Serial.print("number of button pushes:  ");
       Serial.println(buttonPushCounter, DEC);
     } 
     else {
       // if the current state is LOW then the button
       // wend from on to off:
       Serial.println("off"); 
     }
     if ((millis() - lastDebounceTime) > debounceDelay) 
     // whatever the reading is at, it's been there for longer
     // than the debounce delay, so take it as the actual current state:
     
     // save the current state as the last state, 
     //for next time through the loop
     lastButtonState = buttonState;
   }
   // turns on each LED 
   // checking the modulo of the button push counter.
   // the modulo function gives you the remainder of 
   // the division of two numbers:
   if (buttonPushCounter == 2) {
     digitalWrite(led1Pin, HIGH);
     analogWrite(buzzpin, i = 250);
     delay(1000);
     analogWrite(buzzpin, i = 0);
   }
   if (buttonPushCounter  == 3) {
     digitalWrite(led2Pin, HIGH);
   analogWrite(buzzpin, i = 250);
     delay(1000);
     analogWrite(buzzpin, i = 0);
   } 
   if (buttonPushCounter == 4) {
     digitalWrite(led3Pin, HIGH);
     analogWrite(buzzpin, i = 250);
     delay(1000);
     analogWrite(buzzpin, i = 0);
   } 
 }

Write out the steps that you want to have happen when the wires touch:

If the wires are touching, and they were not touching last time we checked, and if it's been a while since we checked, then, increment the touch count and light another LED.

You've got lines 3 and 4 reversed in your code.

You've got lines 3 and 4 reversed in your code.

Thanks for your advice... I'm trying to get my head around it and change what I've done... i"m sure its very simple.

one question... this is going to sound stupid... but I'm a bit confused as to where lines 3 and 4 are and what you mean by this.... are you talking about the comment at the top??

Ni. I mean that in your code you check that the button is pushed (or the lines touch), and that it was not pushed before (or that the lines were not touching before).

   if (buttonState != lastButtonState) {
     lastDebounceTime = millis();
     // if the state has changed, increment the counter
     if (buttonState == HIGH) {

That's line 1 and line 2 of the steps that I think you are trying to implement. (Now that I think about it, I think you are doing these backwards, too.)

Then, you increment the touch count:

       buttonPushCounter++;

That's line 4.

Finally, you look at how long it has been since the wires last touched:

     if ((millis() - lastDebounceTime) > debounceDelay)
     // whatever the reading is at, it's been there for longer
     // than the debounce delay, so take it as the actual current state:

     // save the current state as the last state,
     //for next time through the loop
     lastButtonState = buttonState;

For debouncing, you would see if the wires touched, when they didn't before, and that the time since they last touched was greater than some threshold. The idea is that two touches within 5 milliseconds only counts as one touch.

When you set the contact time, and the action that you take if the time is high enough, are both wrong.

The code should see if the wires are touching (HIGH). Then, it should see if that represents a change in state (not equal to previous state). If both of these conditions are true, then it should check the length of time elapsed since the last change in state (to HIGH). If sufficient time has elapsed, then increment the counter and set a new contact time.

Finally, regardless of whether the wires are now in contact, or not, set the previous state to the current state. Looks something like this:

void loop()
{
    int currentButtonState = digitalRead(buttonPin);
    if(currentButtonState == HIGH && 
          currentButtonState != previousButtonState)
    {
        // Contact was just made. See if it's been long enough...
        if(millis() - previousContactTime > threshold)
        {
            // This counts as a new contact
            buttonPush++; // Light up another LED, too
            previousContactTime = millis(); // Set a new contact time
        }
    }

    previousButtonState = currentButtonState;

    // Now, see if the game is over. User could have reached end, or could
    // have touched too many times. Do whatever is required to start a new
    // game, including setting previousContactTime to 0 and
    // previousButtonState to LOW.
}

Thanks very much for your advice in this...I didn't really look at your code yet, but ill give it a look over now and see if i can tidy up what I have now... In the mean time i was thinking about what you said in your last post, I changed the code around as below and it seems to do what I want...

/*
 Its a buzz off wire contact game, 
I have 3 LED's and a buzzer
each time the handle wire makes contact to the wire game,
the buzzer sounds for 1 second and 1 LED comes on and stays on,
each time the wires make contact the buzzer will sound and another LED lights up and stays on. 
 */


 // this constant won't change:
 const int  buttonPin = 2;    // the pin that the pushbutton is attached to
 const int led1Pin = 11;       // the pin that the LED is attached to
 const int led2Pin = 12; 
 const int led3Pin = 13;
const int buzzpin = 9;         // the pin that the buzzer is attached to 

 // Variables will change:
 int buttonPushCounter = 0;   // counter for the number of button presses
 int buttonState = 0;         // current state of the button
 int lastButtonState = 0;     // previous state of the button
  int i = 0;
  
 // the following variables are long's because the time, measured in miliseconds,
 // will quickly become a bigger number than can be stored in an int.
 long lastDebounceTime = 0;  // the last time the output pin was toggled
 long debounceDelay = 5;    // the debounce time; increase if the output flickers

 void setup() {
   // initialize the button pin as a input:
   pinMode(buttonPin, INPUT);
   // initialize the LED pin as an output:
   pinMode(led1Pin, OUTPUT);
   pinMode(led2Pin, OUTPUT);
   pinMode(led3Pin, OUTPUT);
   pinMode(buzzpin, OUTPUT);
   // initialize serial communication:
   Serial.begin(9600);
 }
 void loop() {
   // read the pushbutton input pin:
   buttonState = digitalRead(buttonPin);
   // compare the buttonState to its previous state
   if (buttonState != lastButtonState) {
     lastDebounceTime = millis();
     
     if (buttonState == HIGH) {  // if the current state is HIGH then the button
       // wend from off to on:
         
        buttonPushCounter++; // if the state has changed, increment the counter
       
       analogWrite(buzzpin, i = 250);  // sound the buzzer
     delay(1000);                          // sound teh busser for 1sec
     analogWrite(buzzpin, i = 0);          // Turn off the buzzer
      
     
       Serial.println("on");
       Serial.print("number of button pushes:  ");
       Serial.println(buttonPushCounter, DEC);
     } 
     else {
       // if the current state is LOW then the button
       // wend from on to off:
       Serial.println("off"); 
     }
     if ((millis() - lastDebounceTime) > debounceDelay) 
     // whatever the reading is at, it's been there for longer
     // than the debounce delay, so take it as the actual current state:
     
     // save the current state as the last state, 
     //for next time through the loop
     lastButtonState = buttonState;
   }
   // turns on each LED every time the counter increments 
   
   if (buttonPushCounter == 1) {
     digitalWrite(led1Pin, HIGH);
   
   }
   if (buttonPushCounter  == 2) {
     digitalWrite(led2Pin, HIGH);

   } 
   if (buttonPushCounter == 3) {
     digitalWrite(led3Pin, HIGH);
  
   } 
 }

I'll try and see if I can tidy up the code a bit more... Ill post the code and layout diagram in the projects section...

Thanks for the help... its giving me a better understanding of how it all works... early days yet in learning a new skill...