New EdgeDebounce feature not working

Hi, Thanks for seeing this. your explanation is clear.

I will rewrite the thing so that the call from the Sketch will look like:

if (button.close() && button.rose()) {
  /Your code here
}

I also like the idea of disabelling the debouncer altogether.

I will get back soon.

Jacques

Hi,

Changed .cpp to:

byte EdgeDebounce::update() {
  byte newStatus = debounce();
  if (MYmode == PULLUP) newStatus = !newStatus;
  if (MYstatus == OPEN && newStatus == CLOSED) { MYrose = true; Serial.print('.'); }
  else                                           MYrose = false; 
  if (MYstatus == CLOSED && newStatus == OPEN) { MYfell = true; Serial.print(':'); }
  else                                           MYfell = false;
  MYstatus = newStatus;
  return newStatus;
}//update-------------------------------------------------------------------------

//statusMethods=====================================================
bool EdgeDebounce::closed() const { return MYstatus; }
bool EdgeDebounce::open()   const { return !MYstatus; }

//transition methods========================================
bool EdgeDebounce::rose() const { return MYrose; }
bool EdgeDebounce::fell() const { return MYfell; }

And sketch to:

#include <EdgeDebounce.h>

EdgeDebounce test(4, PULLUP);

void setup() {
  test.begin();
  Serial.begin(9600);
}

void loop() {
  int theState = test.update();
  if (test.rose()) Serial.print(',');
  if (test.fell()) Serial.print(';');
}

It all works now.

Thanks

Jacques

debounceDontCare = ~((1<<w)-1);

It took me a little while just to understand what the original algorithm:

bool_t DebounceSwitch2()
{
Static uint16_t State = 0;
State=(State<<1) | !RawKeyPressed() | 0xe000;
If(State==0xf000)return TRUE;
Return FALSE;
}

actually did.

I will need some time to figure out your shorthand notation... Learning opportunity :art:

Jacques

It's not shorthand, it's an expression. Suppose you pass in 16 for the variable w.

1UL<<w left-shifts a 1 by 16 spaces, producing the number 0x00010000. Note the UL suffix I added here. It's important and I forgot to put it in the original post.

From this the quantity 1 is subtracted, producing 0x0000FFFF.

~ is a bitwise inversion, producing 0xFFFF0000.

Try it again with 12.

1UL<<12 = 0x00001000
0x00001000 - 1 = 0x00000FFF
~0x00000FFF = 0xFFFFF000

Yes,

I just did some tests in Word (easy to jot down 0s and 1s)

00000000000000010000000000000000
00000000000000001111111111111111
11111111111111110000000000000000

Thanks again