1. Hardware setup (Fig-1) using Button, Led, Pot1, and UNO

Figure-1:
2. You want that when Button of Fig-1 is pressed, the Led should turn ON. The On-period is determined by the voltage level at A0-pin. If you press Button again when the Led is still ON, the MCU/program will ignore the Button action.
Sketch (tested on UNO)
#define Led 13
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(Led, OUTPUT);
analogReference(DEFAULT);
}
void loop()
{
unsigned int timeDelay = map(analogRead(A0), 0, 1023, 0, 5000);//(5000/5)*3.3 =3 sec
bool n = digitalRead(2);
if (n == LOW) //Button is closed
{
digitalWrite(Led, HIGH);
delay(timeDelay);
digitalWrite(Led, LOW);
}
}
3. Note that a mechanical swicth like Button of Fig-1 makes a lot of make-and-break (called bouncing) before settling at the final closed position. In such case, we can apply debouncing on the Button using Debounce.h Library. Debouncing does not stop bouncing; rather, it refers to waiting of about 50 ms (as is set in the Debounce.h Library) until the Button settles at the final closed position.
Sketch: (tested on UNO)
#include<Debounce.h>
Debounce Button(2);
#define Led 13
void setup()
{
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(Led, OUTPUT);
analogReference(DEFAULT);
}
void loop()
{
unsigned int timeDelay = map(analogRead(A0), 0, 1023, 0, 5000);//(5000/5)*3.3 =3 sec
bool n = !Button.read(); //redas Button when it is settled at closed position
//Serial.println(n);
if (n == LOW) //Button is closed
{
digitalWrite(Led, HIGH);
delay(timeDelay);
digitalWrite(Led, LOW);
}
}