Using Bounce library

I've downloaded and installed the Bounce 2 library, I've implemented the code in a sketch:

const int cintPin = 7;
Bounce debouncer1 = Bounce(); 

void setup() {
  pinMode(cintPin, INPUT_PULLUP);
  debouncer1.attach(cintPin);
  debouncer1.interval(5);
  Serial.begin(115200);
}

void loop() {
  debouncer1.update();
  int value = debouncer1.read();
  Serial.print("button on pin 7: ");
  Serial.println(value);
}

I expected to see a steady value of 1 when the button is depressed and 0 when it isn't, what actually happens is it changes between 1 and 0, ok a lot of 1's then a lot of 0's but it isn't fixed, which is what I expected.

I am keeping my finger on the button....

Where did you get the library from? (preferably a link to the github repo, so we can read the library code without downloading anything - a lot of us post here from phones and stuff)

Always post where you got the library from - due in part to the github "fork" feature, identically named but subtly (and unsubtly) different versions of libraries proliferate on the internet, usually without the person who forked them bothering to so much as update the readme.

Besides, you're asking us for help, don't make us dig up the resources we need to help you.

Your code is incomplete. Where is the #include for the library ?

If you had problem to get a steady reading and thought a library would fix it, I am pretty sure your button is broken.

I found a bounce2 in Arduinos library manager, Here it is

@DrAzzy, I got the library from here: Home · thomasfredericks/Bounce2 Wiki · GitHub

@UKHeliBob, yes, I missed it in my post, the include is: #include <Bounce2.h>

@Gabriel_swe, I have lots of the same button, I'll try another.

One thought, the code I posted isn't the full code, and the library isn't interrupt driven so is it possible that time spent doing something else could effect the bounce library?

[Edit] After replacing the button, the code does exactly the same, the button is not the problem.

the code I posted isn't the full code,

Does the code you posted give you the results expected ? If not then further investigation is needed because it cannot be being affected by other code.

Could it be the resistor, I just checked and the one I have is 10K ?

Could it be the resistor,

Which resistor would that be ?

The one between 5v and the pushbutton.

There is a few examples included with the library. I assume they should work perfectly with the library.

File > Examples > (scroll to the bottom if needed) Bounce2 > bounce.

Try them and tell how it worked.

You can specify debounce time for the library, and 5 ms default might be a bit short for some buttons. But it should not affect output for a long solid press as you described in first post.

Added, you have INPUT_PULLUP specified. You should wire your button to ground.

Why have you got an external pullup resistor when you have used INPUT_PULLUP in the pinMode() to activate the built in pullup resistor ?

Remove the external resistor. Wire the switch to take the pin directly to GND when the switch is closed. Job done.

@UKHeliBob, that was it, removing the resistor and connecting directly to the 5v has solved the problem, works perfectly now, thank you.

It shouldn't work at all if you combine INPUT_PULLUP with wiring your button to +5V. It should give a solid HIGH ignoring your push.
Read about INPUT_PULLUP here

removing the resistor and connecting directly to the 5v

I assume that you mean GND rather than 5V. Or do you ?

I have them connected to the 5v on one side and the signal on the other. Is this wrong?

Connect one side of the switch to GND and the other to the input pin. No other connections are needed. INPUT_PULLUP in the pinMode() will keep the pin normally HIGH. Closing the switch will take it LOW. You can detect either state.