single VNH5019 Motor Driver Carrier

I'm in need to control this driver. i don't want to use the shield which is dual because i'm using the ethernet shield. I can't find any on the internet how to program this thing.

Here's the pin i used.

Arduino VNH5019
digital 3-----------------PWM
digital 7-----------------INA
digital 8-----------------INB

Here's the code i wrote.

const int INA = 7;
const int INB = 8;
const int PWM_PIN = 3;


void setup(){

pinMode(INA, OUTPUT);
pinMode(INB, OUTPUT);
pinMode(PWM_PIN, OUTPUT);
Serial.begin();

}

void loop(){
  
if(Serial.available() >=2){
  byte cmd1 = 0;
  byte cmd2 = 0;
  cmd1 = (byte)Serial.read();
  cmd2 = (byte)Serial.read();
  
  if(cmd1=='m' && cmd2=='f'){ // if serial read "mf" forward motor
  
    digitalWrite(INA, HIGH);
    digitalWrite(INB, LOW);    
  }
  else if(cmd1=='r' && cmd2=='m') //if serial read "rm" reverse motor
  
  digitalWrite(INB, HIGH);
  digitalWrite(INA, LOW);
  
if(cmd1=='i' && cmd2=='s'){ // if serial read "is" then increment speed.

How do i speed up motor here?

}
else if(cmd1=='d' && cmd2=='s'){ // if serial read "ds" then decrease speed.

How do i decrease the speed here?

}

}
 
}

How do i control the speed of it?

Thanks.

Use analogWrite on your PWM_pin. Keep the speed in a byte variable, increase and decrease it when your serial commands ask for it, then use it in a call to analogWrite.

Like this?

int speed = 0;

if(cmd1=='i' && cmd2=='s'){ // if serial read "is" then increment speed.

speed++;

analogWrite(PWM_PIN, speed);

}
else if(cmd1=='d' && cmd2=='s'){ // if serial read "ds" then decrease speed.
speed--;
analogWrite(PWM_PIN, speed);

}

What's the max speed btw?

That's it. Max is 255, which is why I suggested storing it in a byte.

Serial.begin();

Does this even compile? The begin method needs to know what speed you want to use.

PaulS:

Serial.begin();

Does this even compile? The begin method needs to know what speed you want to use.

Aw my fault it's Serial.begin(9600);
Is my code correct in increaseing and decreasing speed?