time limit on button press to control memory alloys

Im quite new to coding in arduino.

I am working on a project using memory alloys (muscle wires) i have a pushbutton that when you press will send the current through the memory alloy and cause it contract.
This part i can do. but the alloy is susceptible to over heating so i would like to add a time limit of 10 seconds to the button so even if someone holds it down for 20 seconds the current will automatically cut off after 10.

I have written a code based on my experience in processing but it does not turn off the current after 10 seconds.

this code is just for an led so i can get this part working before i add the extra components associated with the memory alloy

Looking for some advice- if i need to be using the millis function. or a example of a code that would work in this manor

Thanks

const int buttonPin = 2 ;     // the number of the pushbutton pin
const int ledPin = 13 ;    // connected to the base of the transistor

int counter = 0;
boolean counterStat = false;
int maxOn = 10000;

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
 pinMode(ledPin, OUTPUT);   // transistor pin as an output:    
 pinMode(buttonPin, INPUT);     //  pushbutton pin as an input:
 Serial.begin(9600);
}

void loop(){
  
  buttonState = digitalRead(buttonPin);  // read the pushbutton value:
  Serial.println(buttonState); 
  
     
     
     if (counterStat){
   digitalWrite(ledPin, HIGH); //ON
   counter += 1000;
   Serial.println(counter);
   
    if (buttonState == HIGH) {    
    counterStat = true;   
  } 
  else if(buttonState==LOW && counterStat==false) {
    digitalWrite(ledPin, LOW); 
  }
}

   if(counter >= maxOn) {
    counterStat = false;
    counter = 0;
    digitalWrite(ledPin, LOW); //OFF
   
   }
  }

The algorithm you describe would be easy to implement, but means you could probably still overheat things if you hold the power on for ten seconds, release it for a fraction of a second and then hold the power on again. A more robust approach would be to manage the duty cycle i.e. require the power to be on for no more than ten seconds out of every 20 seconds, or something like that. Maybe you just want to implement the simple algorithm to get you started, but that's something you ought to decide for yourself.

Yes, this is something i was going to implement at a later date. as my skills are still limited i wanted to do it one stage at a time

DON'T DOUBLE POST !

I've just spent time responding to the same question in a different Thread. Get the moderator to merge it with this Thread.

...R