Arduino Variable Delay Time

Good day,

I got some problem with the delay function in Arduino. I use Arduino Mega 2560. I want to have code with vary delay time value, some input will change the delay time value.

int x;
int UPtime;

void loop();
UPtime = (175-x)/70;
CW();
delay(UPtime);  
OFFMOTOR();

But when I tried it, the delay time didn't change, the LED just blinking very quick. Hope someone can help me. Thank you.

Hi,
Welcome to the Forum.

delay(1) = 1 millisecond. delay (1000) = 1 second

dividing by 70 with integer variables will also shorten your results to near 0 values if x is < 175.

What length of delay do you want?

You might have more success without using the delay function.

In the IDE Examples, Digital you will find BlinkWithoutDelay, his will help you.

Tom… :slight_smile: