Hi,
Because you are debouncing, you are only counting on the change of your button, not the state of the button.
Your code can be simplified to accomplish what you need, below.
I have just commented out your bit of code and added the edit.
The variable countrate sets how fast the count occurs, the larger the number the slower the rate.
reading2 = digitalRead(CTAmp_button);
/*
if (reading2 != lastButtonState2)
{
lastDebounceTime2 = millis();
}
if ((millis() - lastDebounceTime2) > debounceDelay2)
{
if (reading2 != buttonState2)
{
buttonState2 = reading2;
if (buttonState2 == HIGH)
{
Counter ++;
}
}
}
lastButtonState2 = reading2;
*/
// START ADDED CODE
if (reading2 == HIGH)
{
count++
delay(countrate);
}
// END ADDED CODE
Num = Counter;
a = Num / 1000; //If Num=1234 Then a=1;
temp1 = Num % 1000; //If Num=1234 Then temp1=234;
b = temp1 / 100; //If temp1=234 Then b=2;
temp2 = temp1 % 100; //If temp1=234 Then temp2=34;
c = temp2 / 10; //If temp2=34 Then c=3;
d = temp2 % 10; //If temp2=34 Then d=4;
display (a);
display (b);
display (c);
display (d);
You need to add before void setup()
int countrate = 100;
Hope it does what you need.
Tom... ![]()