L298n Hbridge + Potentiometer

Hi,

Can anyone help me with creating code so that i can use a potentiometer to control the direction and the speed of the motor.

where do i connect the potentiometer?

I current dont have any code.

I am using a DC motor

loop() {
int Aval = analogRead(2) ;
if (Aval>=512) {
  digitalWrite(9,HIGH) ;
  analogWrite(6,map(Aval,512,1023,0,255) ) ;
  } else {
  digitalWrite(9,LOW) ;
  analogWrite(6,map(Aval,0,511,0,255) ) ;
}

Now you just have to work out the circuit.