debouncer

can someone tell me why is don't work when I add long unsigned to" long unsigned currentmillis = millis(); "
at start of main loop . it works perfect if I take "long unsigned "out but it needs it for roll over.
it is a debouncer I made.

unsigned long currentmillis=0;
unsigned long buttonmillis=0;
unsigned long previousmillis=0;
#define led 8
#define D4 4
int button=0;
int buttonTime=200;

void setup() {
Serial.begin(115200);
digitalWrite(D4,INPUT_PULLUP);

}

void loop() {
long unsigned currentmillis = millis();

Button ();

digitalWrite(led,button);

}
//end of program

int Button ()
{
if (digitalRead(D4)==HIGH)
buttonmillis = millis();

if ((unsigned long)(currentmillis-buttonmillis)>=(buttonTime))
{
Serial.println(currentmillis-buttonmillis);

button=1;

;
Serial.println(button);
Serial.println(digitalRead(D4));

}else
{
button=0;
}
return button;
}

Change:
long unsigned currentmillis = millis();
To:
currentmillis = millis();

It's a scope issue.

There is a global variable currentmillis declared as an unsigned long. When you use the global variable, both loop() and Button() can use the global variable, and they use the same one.

When you declare unsigned long currentmillis inside your loop() function, it allocates another local variable named currentmillis, and sets it to millis(). This is not the same variable as the global currentmillis. Your Button() function cannot access the local variable in the loop() function. It uses the global currentmillis variable instead. But that variable has not been set.

thanks that's what I figured , iv only been coding a few days so im not good with this stuff. I fixed by just using the millis() instead of the currentmillis in the time comparator inside the button loop. Thanks for your input. This stuff gets tough.

What do you think this statement does?

;

AARG

Am I using it wrong ? Im not quite sure if your sarcastic or not ?

I assume it to separates out statements . It clearly lays out one line from the next and separates functions from one another .

You have an spurious ;

button=1;
;
Serial.println(button);