int buttonPin=2;
int LEDPin=13;
void setup() {
// put your setup code here, to run once:
pinMode(LEDPin, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(LEDPin,LOW);
}
void loop() {
// put your main code here, to run repeatedly:
int TimeC=0;
//We wait when button is not being pressed as LED will be glowing during this time
while(digitalRead(buttonPin)==LOW)
{
};
//Adjusting for physical bounce of Push Button
delay(20);
while(digitalRead(buttonPin)==HIGH)
{
TimeC++;
delay(1);
//wait one millisecond
}
if(TimeC>0)
{
digitalWrite(LEDPin, HIGH);
delay(TimeC);
digitalWrite(LEDPin, LOW);
}
}