Do you mean using a timer (like millis() function or similar) instead of a delay in between the output LED digitalwrite() function (HIGH and LOW). Could you please explain more?
Hello yes millisecond , i need to put another switch with other output wich trigger other relay with a different time ( in milliseconds).
That is why i need to put a millis instead of delay.
I tryed with same functions used in ( blink without delay) but it stay always on after i push switch button…
Thank you….
Try this, the below code checks whether the time equal to delay is passed since the output is switched ON, if the time in millis() after switch ON is greater than set delay then it will switch OFF the output.
/*
long time_millis = 0;//Intialize as long
delay_time = 100; //In seconds
*/
if (buttonState == HIGH && prestate == 0) {
count_value++; Serial.println(count_value);
// turn LED on
digitalWrite(ledPin, HIGH);
time_millis = millis();
prestate = 1;
} else if (buttonState == LOW) {
prestate = 0;
}
// turn LED off
if ((millis() – time_millis) > (delay_time * 1000)) {
digitalWrite(ledPin, LOW);
}
Do you mean using a timer (like millis() function or similar) instead of a delay in between the output LED digitalwrite() function (HIGH and LOW). Could you please explain more?
Hello yes millisecond , i need to put another switch with other output wich trigger other relay with a different time ( in milliseconds).
That is why i need to put a millis instead of delay.
I tryed with same functions used in ( blink without delay) but it stay always on after i push switch button…
Thank you….
Try this, the below code checks whether the time equal to delay is passed since the output is switched ON, if the time in millis() after switch ON is greater than set delay then it will switch OFF the output.
/*
long time_millis = 0;//Intialize as long
delay_time = 100; //In seconds
*/
if (buttonState == HIGH && prestate == 0) {
count_value++;
Serial.println(count_value);
// turn LED on
digitalWrite(ledPin, HIGH);
time_millis = millis();
prestate = 1;
} else if (buttonState == LOW) {
prestate = 0;
}
// turn LED off
if ((millis() – time_millis) > (delay_time * 1000)) {
digitalWrite(ledPin, LOW);
}