Help using millis() instead of Delay()

I have to control the speed of a servo motor and change it with a button using a counter. The problem is that I'm using the Delay() function to control the speed, but when I press the button the counter doesn't go up due to the delay function. The code about the counter is right, I tried it without the delay. I researched for a solution and I know I have to use the millis() function, but in the examples I see online they don't necessary use millis() depending on an counter. The part of the code I want to change is this one:

switch(counter){
case 1:

myServo.write(0);
delay(2000);
myServo.write(165);
delay(800);
old = counter;

break;

case 2:


myServo.write(0);

delay(1000);
myServo.write(165);
delay(500);
old = counter;

break;

P.S. Sorry for errors , english is not my mother language

Check out my tutorials on
How to write Timers and Delays in Arduino
and
Multi-tasking in Arduino

1 Like

Thank you

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.