So, the problem is my motor doesnt change its direction after the first FOR loop is finished. I it keeps on running on the initial condition whether the initial condition i give is forward or reverse it keeps that direction and doesnt go opposite.
Heres my code to get an idea
const int ENA = 11;
const int IN1 = 12;
const int IN2 = 8;
const int ENB = 6;
const int IN3 = 4;
const int IN4 = 2;
void setup()
{
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop()
{
digitalWrite(IN1, HIGH); //FORWARD
digitalWrite(IN2, LOW);
for(byte i = 0; i < 256; i++) //Accelerate
{
analogWrite(ENA, i);
delay(100);
}
delay(2000);
digitalWrite(IN1, LOW); //reverse
digitalWrite(IN2, HIGH);
for(byte i=0; i < 256; i++)
{
analogWrite(ENA, i);
delay(100);
}