Can't get bounce object to update (boneheaded oversight?)

Status
Not open for further replies.

oddson

Well-known member
Simple code... returns 'fail'...

Tried to add a debounced button to an existing MIDI sketch and it didn't work.

Stripped everything out of the sketch leaving just this:
Code:
#include <Bounce.h> 
Bounce button0 =   Bounce(0,10);
void setup() {
  Serial.begin(9600);
}
void loop() {
  if (button0.update()) {
    if (button0.fallingEdge()) {
      Serial.println("fall");
    }
    if (button0.risingEdge()) {
      Serial.println("rise");
    }
  }else{
    Serial.println("fail");
    delay(2000);
  }
}
Prints 'fail' every time. :(

I know I'll be embarrassed... anyone know what I'm missing?

edit - compiling as 'Serial' but the problem appeared with (usb)MIDI selected.
 
Last edited:
Yeah that kinda bone-head thing....

You'd think that would have stood out as I stripped away everything else but I'd become blind to it...

(edit - apart from alcohol consumption it is looks like the explanation for my stupidity is that my old code had a loop setting the pull-ups but I didn't convert it to the scalar variable for the single bounce sketch I was building. When it didn't work and I was troubleshooting I stripped out the 'other' code and the pull-up loop got stripped too... doesn't explain why I couldn't see it.)
 
Last edited:
Status
Not open for further replies.
Back
Top