Running a continuous servo for a specific amount of time without a delay

I am trying to write an if else statement that activates a continuous servo motor for x amount of time, then stops and is only activated again once the else part of the statement is triggered. Is this possible? I tried doing it with a delay but it just looped back through the if statement once the delay ended, which I don't want. I also tried to use a 180 servo but I need it to do 3 full rotations, which that servo isn't capable of.

Any ideas?

sabbicat:
Any ideas?

First, you need to post the program you have tried so we can see it.

Second, have you considered a sail-winch servo which can do 3 turns (some of them more) with position control.

Third, the demo Several Things at a Time illustrates the use of millis() to manage timing without blocking. It may help with understanding the technique.

Have a look at Using millis() for timing. A beginners guide if you need more explanation.

...R

I tried doing it with a delay but it just looped back through the if statement once the delay ended,

That has nothing to do with the sort of delay you used but the way you have written your code that surrounds the delay, when you post your code we can see what.

Here was my attempt, mostly at this point I'm just confusing myself.

#include <Servo.h>


unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
int interval = 1000;

int reading = 0;
int openThreshold = 900;
int closeThreshold = 200;
int closeFlower = 110;
int openFlower = 70;
int neutralFlower = 90;
Servo myservo;

void setup() {
Serial.begin(9600);
myservo.attach(9);
myservo.write(neutralFlower);

}
void loop() {
reading = analogRead(A0);
unsigned long currentMillis = millis();
//  Serial.println(reading);

if (currentMillis - previousMillis1 >= interval) {
  previousMillis1 = currentMillis;
  if (previousMillis1 < 2000) {
    if (reading > openThreshold) {
      myservo.write(openFlower);
      Serial.println("open");
    }
  }
}
else {
  myservo.write(neutralFlower);
  previousMillis1 = 0;
}

if (currentMillis - previousMillis2 >= interval) {
  previousMillis2 = currentMillis;
  if (previousMillis2 < 2000) {
    if (reading < closeThreshold) {
      myservo.write(closeFlower);
      Serial.println("close");
    }
  }
}
else {
  myservo.write(neutralFlower);
  previousMillis2 = 0;
}

}

sabbicat:
Here was my attempt, mostly at this point I'm just confusing myself.

if (currentMillis - previousMillis2 >= interval) {

previousMillis2 = currentMillis;
  if (previousMillis2 < 2000) {

For both variables called previousMillisX, your setting them to current millis and then expecting them to be less than 2000 to trigger your if statements..

Well unless your arduino has been on for less than 2 seconds, or has been on for something like 50 days till it flips back to zero, your currentmillis is going to be greater than 2000 so it doesn’t do anything.