arduino met relay control en Timer restart how to do?

dit is versie 1.1 met aanpassing zoals jij voorsteld
wat vind je hier van?

//This example code is in the public domain.

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 3; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
const int ledPin2 = 14; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
digitalWrite(ledPin, HIGH);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
balance() ;
}
else {
// turn LED off:
loop() ;
}

}

void balance()
{
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
unsigned long starttime = 0;
unsigned long endtime = 0;
starttime = millis(); // set current time of system
endtime = starttime + 5000; // timer in miliseconds test set to 5 seconden

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (millis() > endtime) { //over time
digitalWrite(ledPin, LOW); //relais off
delay(500);
}
else {
// turn LED off:
digitalWrite(ledPin2, LOW);
}
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}