Debounce on a Pushbutton

yes I am absolutely looking at the delay stuff. I am trying to sort out when and everything these delays are occurring to try and see if they take place when the buttons are to be pushed. looking at the delay the part that doesn't make sense to me is I can stand there for any amount of time say 1 minute so the delay should be out of the way I think and even just pressing the first button fast it still wont accept. wouldn't the delay be over and it is just listening at that point?

I'm not sure your problem has anything to do with button bouncing at all.

I don't see where the buttons are actually read, digitalRead().

I agree w/ @cattledog that no one is likely to build your project, or even get all the code out where it can be analysed in any way.

If you have no further information, no website or other explanation of the code, you may get less help.

You d ino,ied there is already circuitry you cannot modify, are you with a PCB of some kind? Maybe take a few pictures of your project.

It would be a bit of a nightmare, but one way to show us all how this doesn't work would be to build it in the wokwi simulator:

a7

so I'm not really looking for any code to be written for me. I just asked if anyone sees something that is a button debounce as I have never done that and don't know what it would look like. The program does work I just don't like that a quick button press doesn't register. You need to press the button more deliberately than I would like so i want to figure out why that is. On the PCB i don't see any capacitors really and from what people have said each button would need one so that would be 16 of them. I think this is where that may be happening.

#include "ArdPin.h"

ArdPin::ArdPin(int pin, unsigned long requestDuration) {
  _callbackOnChanged = NULL;
  
  //  save vars  //
  _pin = pin;
  _requestDuration = requestDuration;

  //  set pin to input  //
  pinMode(_pin, INPUT_PULLUP);
  
  //  flags  //
  _lastValue = -1;
  
  isHighDetected = false;
  valueHigh_ts = 0;
  isLowDetected = false;
  valueLow_ts = 0;
}

void ArdPin::setCallbackOnChanged(void (*callbackOnChanged)(bool newState)) {  
  //  save callback  //
  _callbackOnChanged = callbackOnChanged;
}

bool ArdPin::getDirectValue() {
  return (digitalRead(_pin) == HIGH);
}

void ArdPin::check() {
	
  //  get value  //
  bool currentValue = getDirectValue();	
	
  //  check HIGH  //
  if(currentValue) {
	
	//  check new HIGH  //
	if(_lastValue == LOW) {
		
		//  save ts  //
		valueHigh_ts = millis();
	}
	
	//  check after delay (once)  //
	if(millis() - valueHigh_ts > _requestDuration
	&& isHighDetected == false) {
		
		//  set flag  //
		isHighDetected = true;
		
		onChanged(HIGH);
	}
	
	//  clear flag  //
	isLowDetected = false;
  }
  
  //  check LOW  //
  else {
  
  	//  check new LOW  //
	if(_lastValue == HIGH) {
		
		//  save ts  //
		valueLow_ts = millis();
	}
		
	//  check after delay (once)  //
	if(millis() - valueLow_ts > _requestDuration
	&& isLowDetected == false) {
		
		//  set flag  //
		isLowDetected = true;
		
		onChanged(LOW);
	}
	
	//  clear flag  //
	isHighDetected = false;
  }
  
  //  save value  //
  _lastValue = currentValue;
}

void ArdPin::onChanged(bool newState) {
	//  emit onChanged  //
	if(_callbackOnChanged != NULL) {
		_callbackOnChanged(newState);
	}
}

int ArdPin::getValue() {
	if(isHighDetected) {
		return 1;
	}
	else if(isLowDetected) {
		return 0;
	}
	else {
		return -1;
	}
}

and that library is used for this

#include <ArdPin.h>
#include <ArdSensor.h>

#define BTNS_COUNT 16

int PINS_BTNS[BTNS_COUNT] = {36,38,31,30,35,39,37,28,41,40,42,32,33,29,34,27};
                             
bool btns_lastValues[BTNS_COUNT];

ArdSensor* btnsList[BTNS_COUNT];

void btns_init() {
  for(int i = 0; i < BTNS_COUNT; i++) {
    btnsList[i] = new ArdSensor(PINS_BTNS[i], LOW, 50);  
    btns_lastValues[i] = 0;
  }
}

extern void btns_onNewPressed(int index);

void btns_check() {
  for(int i = 0; i < BTNS_COUNT; i++) {
    btnsList[i]->check();
    //  check new  //
    bool current = btnsList[i]->isActivating();
    if(current != btns_lastValues[i]) {
      btns_lastValues[i] = current;
      if (current == 1) {
        btns_onNewPressed(i);
      }
    }
  }
}

void btns_debug() {
  for(int i = 0; i < BTNS_COUNT; i++) {
    btnsList[i]->check();
    Serial.println("Table reeds " + String(i) + ": " + String(btnsList[i]->isActivating())
      + ": " + String(btnsList[i]->getDirectValue()));
  }

  Serial.println();
}

Maybe. Hard to say.

This looks like the debounce interval

50

Un-clever programming would mean a 50 millisecond delay. Some would notice this as sluggish.

Better debouncing for pushbuttons would respond in better time.

But neither 0 no 50 milliseconds is likely to be the problem.

Doing things like this

delay(100);
btnsLeds_clear();
delay(100);

all over the place is more likely to be.

We could replace delay() with a function that would turn on an LED during all those periods when you have deliberately halted all progress and blinded your process from regular inputs.

Then you would prolly see that LED on quite a bit.

Or any number of other approaches. Trouble is, we have not the ability to run your code. I bet no one will build it and see... You may have posted all the tab code, but did not provide the file names - yes, we could figure it out, no we aren't going to: the beach is calling... this is your trip.

Looks Like you are going to have to figure out how this software works, or dump it and write something that does that same thing only better.

a7