long Time = 0;
#define SW 5
#define led 13

#define drebezg 300 //drebezg knopki 300 ms
bool knopka = false;
bool impuls = false;

void setup() 
{
pinMode(SW, INPUT_PULLUP);
pinMode(led, OUTPUT);
}

void loop() 
{
Time = map(analogRead(A0), 0, 1023, 0, 1000);

if (digitalRead(SW) == 0)
{
  knopka = true;
}

//Esli knopka nazata, no impulsa eshche nebylo, dat impuls
if (knopka == true && impuls == false)
{
  digitalWrite(led, 1);
  delay(Time);
  digitalWrite(led, 0);
  impuls = true;  //impusl uze byl
  //Esli Time koroche drebezga
  if (knopka == true && Time < drebezg)
  {
    delay(drebezg -Time);
  }
}

//Esli otpustili knopku
if (digitalRead(SW) == 1)
{
  if (knopka == true)
  {
    //prozgdat drebezg otpuskanija knopki
    delay(drebezg);
  }
  knopka = false;
  impuls = false;
}

}