Motor direction in a countdown timer

Hello. New here.
I am trying to change the motor direction over the countdown but can’t figure out how.
Ideally the motor should rotate for 10 minutes and then change direction and rotate backwards.
The total time is 50 minutes.
Here’s the code:

//Written by Nick Koumaris
//info@educ8s.tv
//educ8s.tv
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
int S = 00; // count seconds
int M = 50; // count minutes
int H = 00; // count hours
const int motorPin1 = 9; // Pin 14 of L293
const int motorPin2 = 10; // Pin 10 of L293
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
void setup()
{
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);

lcd.begin(16,2);//set up the LCD’s number of columns and rows
}
void loop()
{

lcd.setCursor(2,0);
lcd.print (“Tili-Tumb 2”);
lcd.setCursor(6,1);
lcd.print(":");
lcd.setCursor(9,1);
lcd.print(":");
S–;
delay(1000);
if((S == 0) && (M == 0))
{
lcd.setCursor(0, 1); // Positions the cursor on the fourteenth column (13) and the second line (1) LCD
lcd.print(" Fin de ciclo"); // Write the current value of the count variable in the LCD
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 0);
exit(0);
}
else
{

if(S<0)
{
M–;
S=59;
}
if(M<0)
{
H–;
M=59;
}
if(H<0) { H=23; M=59; S=59; } if(M>9)
{
lcd.setCursor(7,1);
lcd.print(M);
}
else
{
lcd.setCursor(7,1);
lcd.print(“0”);
lcd.setCursor(8,1);
lcd.print(M);
lcd.setCursor(9,1);
lcd.print(":");
}
if(S>9)
{
lcd.setCursor(10,1);
lcd.print(S);
}
else
{
lcd.setCursor(10,1);
lcd.print(“0”);
lcd.setCursor(11,1);
lcd.print(S);
lcd.setCursor(12,1);
lcd.print(" “);
}
if(H>9)
{
lcd.setCursor(4,1);
//lcd.print (H);
}
else
{
lcd.setCursor(4,1);
lcd.print(“0”);
lcd.setCursor(5,1);
lcd.print(H);
lcd.setCursor(6,1);
lcd.print(”:");

}

if((S == 0) && (M < 10))
{
//This code will turn Motor A clockwise
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 255);

}
else
analogWrite(motorPin1, 0);
analogWrite(motorPin2, 255);

}}

Your last if block looks not very correct. Change it to …

if((S == 0) && (M < 10)) 
{
    //This code  will turn Motor A clockwise
    analogWrite(motorPin1, 0);
    analogWrite(motorPin2, 255);   
}
else
{
    analogWrite(motorPin1, 255);
    analogWrite(motorPin2, 0);   
    
}

}

  • The else part needs correct paranthesis.
  • The analogWrite signals should have opoosit values in else part.

Thanks I will give it shot