# Performing a motor loop after x time

this is my code >

//2-Way motor control

int motorPin1 = 5; // One motor wire connected to digital pin 5
int motorPin2 = 6; // One motor wire connected to digital pin 6

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pins as an output:
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
rotateLeft(1500, 100000);
rotateRight(1500, 100000);
}

void rotateLeft(int speedOfRotate, int length){
analogWrite(motorPin1, speedOfRotate); //rotates motor
digitalWrite(motorPin2, LOW); // set the Pin motorPin2 LOW
delay(length); //waits
digitalWrite(motorPin1, LOW); // set the Pin motorPin1 LOW
}

void rotateRight(int speedOfRotate, int length){
analogWrite(motorPin2, speedOfRotate); //rotates motor
digitalWrite(motorPin1, LOW); // set the Pin motorPin1 LOW
delay(length); //waits
digitalWrite(motorPin2, LOW); // set the Pin motorPin2 LOW
}

how can i repeat rorate right after 6 hours and repeat left?
e.g.

1.. hours
2
3
4
5
6 > rorate left

7.. hours
8
9
10
11
12 > rorate right
13
14
15
16
17
18 > rorate left
19
20
21
22
23
24 > rorate fight

how can i repeat rorate right after 6 hours and repeat left?

Add a delay() call after each rotation. Figure out how many milliseconds 6 hours is.

Check the count limit for the ms timer, 360,000 may be too big. If so, slow the clock down.

PaulS:
Add a delay() call after each rotation. Figure out how many milliseconds 6 hours is.

Thank you my friend!

6 hours = 21 600 000 milliseconds

the code now is

//2-Way motor control

int motorPin1 = 5; // One motor wire connected to digital pin 5
int motorPin2 = 6; // One motor wire connected to digital pin 6

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pins as an output:
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
}

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
rotateLeft(1500, 100000);
delay(21600000);
rotateRight(1500, 100000);
delay(21600000);
}

void rotateLeft(int speedOfRotate, int length){
analogWrite(motorPin1, speedOfRotate); //rotates motor
digitalWrite(motorPin2, LOW); // set the Pin motorPin2 LOW
delay(length); //waits
digitalWrite(motorPin1, LOW); // set the Pin motorPin1 LOW
}

void rotateRight(int speedOfRotate, int length){
analogWrite(motorPin2, speedOfRotate); //rotates motor
digitalWrite(motorPin1, LOW); // set the Pin motorPin1 LOW
delay(length); //waits
digitalWrite(motorPin2, LOW); // set the Pin motorPin2 LOW
}