It looks like you were very close with the firs program you posted. Here it is in code tags and without the commented lines which only serve to confuse. I have also reformatted it to make it easier to read.
#include <AFMotor.h>
int potentiometerPin = 7; // analog pin used to connect the potentiometer
int potentiometerValue; // variable to read the value from the analog pin
AF_DCMotor left1stMotor(1); // 1. motor ( Left back motor )
int i;
void setup()
{
Serial.begin(9600); // set up Serial library at 9600 bps
left1stMotor.setSpeed(200);
left1stMotor.run(RELEASE);
}
void loop()
{
potentiometerValue = analogRead(potentiometerPin); // reads the value of the potentiometer (value between 0 and 1023)
potentiometerValue = map(potentiometerValue, 0, 1023, 0, 255); //use this line or the next line but not both
potentiometerValue = potentiometerValue/4;
Serial.print("tick");
left1stMotor.run(FORWARD);
for (i=0; i<255; i++)
{
if(potentiometerValue <= 127)
{
left1stMotor.setSpeed(i);
delay(10);
}
}
Serial.print("tock");
left1stMotor.run(BACKWARD);
for (i=0; i<255; i++)
{
if(potentiometerValue >= 127)
{
left1stMotor.setSpeed(i);
delay(10);
}
}
Serial.print("tech");
left1stMotor.run(RELEASE);
delay(1000);
}
Note my comment about using one line or the other but not both. The first line maps the 0 to 1023 value to 0 to 255 then the second line divides the answer by 4. Will the result ever be greater than 127 ?
What does the 1 in this line do ?
AF_DCMotor left1stMotor(1);Does it mean that you are using digital pin 1 ? If so then it will conflict with Serial.print() and vice versa.