NOOB - having problems with loop in code

I am trying to test my motors the code works great till i have dont motor A forward but it keeps looping and not moving on to motor A reverse, can anyone nudge me in the right direction please?

const int ENA = (5, 3); // 3 = GRAY, 5 = ORANGE PWR
const int IN1 = 2; // PURPLE motor A motor F
const int IN2 = 4; // GREEN motor A motor R
const int ENB = (4, 5); // 4 = WHITE, 5 = BLUE PWR
const int IN3 = 10; // YELLOW motor ab motor fb
const int IN4 = 11; // BROWN motor ab motor fb

void setup()
{
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

Serial.begin(9600);
Serial.print(" Beginning motor test… ");

}

void loop()
{
// Motor A testing
digitalWrite(IN1, HIGH); // FORWARD
digitalWrite(IN2, LOW);

Serial.print(" Motor A - FORWARD - Accelerate “);
for(byte i = 0; i < 256; i++) //Motor A - FORWARD - Accelerate
{
Serial.print(i);
analogWrite(ENA, i);
delay(250);
Serial.print(” ");
}

Serial.print(" Motor A - FORWARD - Hold top speed “);
for(byte j=5; j>0; j–) //Motor A - FOPWARD - Hold top speed
{
Serial.print(” ");
Serial.print(j);
delay(500);
}

}

Hello! You must put the code inside the "code" tag instead of the "quote" tag.

EDIT: I don't understand too what is you complain about the motor.

gizzmo341:
not moving on to motor A reverse, can anyone nudge me in the right direction please?

Have you tried adding some code to make motor A run in reverse?

I can’t see any.

…R

the motor will do the accelerate but then just loops and starts accelerating from 0 again i need help with the code moving on to the next step Holding top speed.

[/quote]

Have you tried adding some code to make motor A run in reverse?

[/quote]

i will try this now

const int ENA = (5, 3);  // 3 = GRAY, 5 = ORANGE PWR
const int IN1 = 2;       // PURPLE motor A motor F
const int IN2 = 4;       // GREEN motor A motor R
const int ENB = (4, 5);  // 4 = WHITE, 5 = BLUE PWR
const int IN3 = 10;      // YELLOW motor ab motor fb
const int IN4 = 11;      // BROWN motor ab motor fb
 
void setup()
{
  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENB, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
 
  Serial.begin(9600);
  Serial.print(" Beginning motor test... ");

}
 
void loop()
{ 
    // Motor A testing
    digitalWrite(IN1, HIGH); // FORWARD
    digitalWrite(IN2, LOW);

Serial.print(" Motor A - FORWARD - Accelerate ");
  for(byte i = 0; i < 256; i++) //Motor A - FORWARD - Accelerate
  {
    
    Serial.print(i);
    analogWrite(ENA, i);
    delay(250);
    Serial.print("   ");
  }


//  for(byte j=5; j>0; j--) //Motor A - FOPWARD - Hold top speed
//  {
//    Serial.print(" Motor A - FORWARD - Hold top speed ");
//    Serial.print("   ");
//    Serial.print(j);
//    delay(500);
//  }

 digitalWrite (IN1, LOW); // REVERSE
 digitalWrite(IN2, HIGH);
     Serial.print("Motor A - REVERSE - Accelerate");
  for(byte h = 0; h < 256; h++) // Motor A - Accelerate
  {

    Serial.print(h);
    analogWrite(ENA, h);
    delay(250);
    Serial.print("   ");
  }
}

Same thing just loops back to accelerate

for(byte i = 0; i < 256; i++)

That’s pretty infinite.
Try “int”

AWOL:
Try “int”

too this?

for(int i = 0; i < 256; i++) //Motor A - FORWARD - Accelerate

THANK YOU!!!!!! changing it to int worked it now works and goes from accelerate to reverse

Have you figured out why "byte" (aka uint8_t) didn't work?

AWOL:

for(byte i = 0; i < 256; i++)

That’s pretty infinite.
Try “int”

Oops - never spotted that :frowning:

…R