l298n

i need some assistance on this …
// Move Motor A Forward and Backwards x axis
//Move Motor B (actuator) UP/DOWN y Axis

// Motor A

int enA = 10;
int in1 = 8;
int in2 = 7;

// Joystick Input

int joyVert = A2; // Vertical
int joyHorz = A1; // Horizontal

// Motor Speed Values - Start at zero

int MotorSpeed1 = 0;

// Joystick Values - Start at 512 (middle position)

int joyposVert = 512;
int joyposHorz = 512;

void setup()

{

// Set all the motor control pins to outputs

pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);

// Start with motors disabled and direction forward

// Motor A

digitalWrite(enA, LOW);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

}

void loop() {

// Read the Joystick X and Y positions

joyposVert = analogRead(joyVert);
joyposHorz = analogRead(joyHorz);

// Determine if this is a forward or backward motion
// Do this by reading the Verticle Value
// Apply results to MotorSpeed and to Direction

if (joyposVert > 564)
{
// This is Forward

// Set Motor A forward

digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);

// Set Motor B forward

//Determine Motor Speeds

MotorSpeed1 = map(joyposVert, 564, 1023, 0, 255);
}
else if (joyposVert < 460)
{
// This is Backward

// Set Motor A backward

digitalWrite(in2, HIGH);
digitalWrite(in1, LOW );

// Set Motor B backward

//Determine Motor Speeds

// As we are going backwards we need to reverse readings

joyposVert = joyposVert -460;
joyposVert = joyposVert * -1;

MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);

}

// Adjust to prevent “buzzing” at very low speed

// Set the motor speeds

analogWrite(enA, MotorSpeed1);

}

Working on one axis and one motor only right now. my axis moves the motor A forward(right). when moving joystick in opposite direction… no movement. If i change the digitalWrite HIgh, lOW as the Forward to match the Forward comand… it activates the motor in with movement of joystick LEFT/RIGHT but only moving motor in one direction.

I want… to operate one motor LEFT/RIGHT with one potentiometer(joystick axis) using an l298N H bridge.

HEEEELP.
CHris

You need to put your code in code tags as explained in the How to use this forum - please read. single-post sticky topic, second from the top of this forum section.

  joyposVert = joyposVert -460;
 joyposVert = joyposVert * -1;
 
  MotorSpeed1 = map(joyposVert, 0, 460, 0, 255);

Those first two lines should not be there.

Arduinos mostly have small RAM, unlike say a PC. Don't use an int where a byte variable will do, like for pin numbers.