Putting a timed case in case switch functions

For my last case I want to make the response that is triggered to a servo motor that moves one direction for 3 seconds and then other direction for 6 seconds, and then back to the midpoint in three seconds. This is what I have so far: MeLineFollower lineFinder(PORT_3); void setup() { // put your setup code here, to run once: Serial.begin(9600); rightleg.attach(A2); //attach the right leg servo to pin A2 leftleg.attach(A3); //attach the left leg servo to pin A# arm.attach(0); //attach the servo arm to pin 0 }

void loop() { // put your main code here, to run repeatedly: int sensorState = lineFinder.readSensors(); switch(sensorState) { case S1_IN_S2_IN: //bothh sensors are on the black line so we want the robot to go foward rightleg.writeMicroseconds(850); //right leg turns clockwise to make robot go foward leftleg.writeMicroseconds(850); //left leg turns clockwise to make robot go foward break; case S1_IN_S2_OUT: Serial.println("Sensor 2 is outside of black line"); //right leg needs to go faster than left leg so that both sensors can find the black line rightleg.writeMicroseconds(850); leftleg.writeMicroseconds(1000); //left leg continues to move foward but slower than right leg allowing the worm to find the path again break; case S1_OUT_S2_IN: Serial.println("Sensor 1 is outside of black line"); rightleg.writeMicroseconds(1000); //right leg moes slower than left leg in order for the robot to find the line again leftleg.writeMicroseconds(850); break; case S1_OUT_S2_OUT: Serial.println("Sensor 1 and 2 are outside of black line");//when the worm moves of the blackline it should stop and turn the tail //move tail to left for three seconds //move tail to right for six seconds //move tail to left for three seconds } delay(200); } Im trying to figure out how I should accomplish the last case

 Serial.begin(9600);
 rightleg.attach(A2); //attach the right leg servo to pin A2
 leftleg.attach(A3); //attach the left leg servo to pin A#
 arm.attach(0); //attach the servo arm to pin 0

You can't attach a servo to the hardware serial pin if you are using it for hardware serial.

    //move tail to left for three seconds
    //move tail to right for six seconds
    //move tail to left for three seconds

You have a right leg, a left leg, and an arm. What tail are you talking about?

This is a job for a state-machine I think. Learn about state machines, ie states and transitions, and draw one out for your wanted behaviour - then it should be clearer about how to code this.

The functions delay() and delayMicroseconds() block the Arduino until they complete. Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...T