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.
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.
@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.
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.
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.
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
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.