DC Motor help!!!

Still can not get a dc motor to run in forward and reverse with speed control using a joystick to control both. I’ve searched high and low for libraries but can get any of them to work (I am very new to writing code). I ran the AF_Motor test and the motor runs so i know that the board and the motor are good. This is the code that i have come up with so far, it reads perfect in the serial monitor but the motor still does not turn (or do anything for that fact!!!). starting to get frustrated and need help

#include <AFMotor.h>

AF_DCMotor motor(2);

const int PotPin = A0; // Change this if pot is connected to another pin

int direction = FORWARD; // Where we are going
int speed = 0; // How fast
int potVal = 506; // Current potvalue

void setup() {
// initialize serial communication at 9600 bits per second:



void loop() {
// read the input on the pot:
potVal = analogRead(PotPin);
if (potVal < 506)
{ // Smaller than 512 so we’re going forward
direction = FORWARD;
// Map value from pot-range to motorspeed-range
speed = map(potVal, 0, 506, 255, 0);
{ // Otherwise, we’re going backward
direction = BACKWARD;
// Map value from pot-range to motorspeed-range
speed = map(potVal, 507, 1024, 0, 255);

// print out the variables:
Serial.print("Read: “);
Serial.print(” direction: “);
if (direction==FORWARD)
Serial.print(” Speed: ");
Serial.println(speed); // End of line, so also make it go a line

delay(1); // delay in between reads for stability

Don’t you need some lines like these in your loop() code?

delay(1000); // run forward for 1 second
delay(100); // ‘coast’ for 1/10 second

There you go being technical again....