I like names that look like they should reasonably be expected to be related, like currSwitchState and prevSwitchState. I do not like random names like btnState and buttonLast. They do not look related at all.
I like for people to state how the switches are actually connected to the Arduino.
void loop()
{ btnState = digitalRead(btn);
I like for people to not put ANYTHING after the {.
int buttonLast = 0; // buffered value of the button's previous state
I like for people to use HIGH and LOW when referring to switch states.
if (btnState == LOW && buttonLast == HIGH && (millis() - btnUpTime) > long(debounce))
I like for people to use appropriate types, and to recognize when casts are necessary, and when they just add clutter. I like when people do proper casting, and not use those stupid macros.
while (counter < 6) {
delay (1000);
Weld(100, 500);
counter++;
}
counter = 0;
I like when people use for statements, instead of while statements when the number of iterations is fixed. I like when people initialize variables before they expect them to have certain values.
I think you should look at the state change detection example. There are things you want to do when the switch changes state, regardless of which change occurred. So, create a block that just determines if a state change occurred.
There are things that should be done if the state change happened long enough after the previous state change, so put another if statement inside the state change body.
There are things that should be done if the state changed to pressed, and things that should be done if the state changed to released. So, put another if statement and an else statement in the if long enough between events block.
That if and else statement should call a function to actually perform the work.
There are things that should happen even if the switch has not changed state, so do those after the if state changed statement’s body.
This part checks if the key is pressed
Actually, it doesn’t. It checks that the switch HAS BECOME pressed (not IS pressed).