Need Help how to control 4 dc motors with 2 potentiometers atAdafruitMotorShield

that " 1 " representing the M1 ( motor 1 ) on the adafruit motor shield.

Some informations about adafruit motor shield ( this one is for version 2 motor shield ) :

class Adafruit_MotorShield;
The Adafruit_MotorShield class represents a motor shield and must be instantiated before any DCMotors or StepperMotors can be used. You will need to declare one Adafruit_MotorShield for each shield in your system.

Adafruit_MotorShield(uint8_t addr = 0x60);
The constructor takes one optional parameter to specify the i2c address of the shield. The default address of the constructor (0x60) matches the default address of the boards as shipped. If you have more than one shield in your system, each shield must have a unique address.

void begin(uint16_t freq = 1600);
begin() must be called in setup() to initialize the shield. An optional frequency parameter can be used to specify something other than the default maximum: 1.6KHz PWM frequency.

Adafruit_DCMotor *getMotor(uint8_t n);
This function returns one of 4 pre-defined DC motor objects controlled by the shield. The parameter specifies the associated motor channel: 1-4.

Adafruit_StepperMotor *getStepper(uint16_t steps, uint8_t n);
This function returns one of 2 pre-defined stepper motor objects controlled by the shield.
The first parameter specifies the number of steps per revolution.
The second parameter specifies the associated stepper channel: 1-2.

void setPWM(uint8_t pin, uint16_t val);
void setPin(uint8_t pin, boolean val);
These are low-level functions to control pins on the on-board PWM driver chip. These functions are intended for internal use only.

Connecting DC Motors
To connect a motor, simply solder two wires to the terminals and then connect them to either the M1, M2, M3, or M4. Then follow these steps in your sketch
Include the required libraries
Make sure you #include the required libraries
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Create the Adafruit_MotorShield object
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Create the DC motor object
Request the Stepper motor from the Adafruit_MotorShield:
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
with getMotor(port#). Port# is which port it is connected to. If you're using M1 its 1, M2 use 2, M3 use 3 and M4 use 4

Connect to the Controller
In your setup() function, call 'begin()" on the Adafruit_MotorShield object:

AFMS.begin();
Set default speed
Set the speed of the motor using setSpeed(speed) where the speed ranges from 0 (stopped) to 255 (full speed). You can set the speed whenever you want.
myMotor->setSpeed(100);
Run the motor
To run the motor, call run(direction) where direction is FORWARD, BACKWARD or RELEASE. Of course, the Arduino doesn't actually know if the motor is 'forward' or 'backward', so if you want to change which way it thinks is forward, simply swap the two wires from the motor to the shield.
myMotor->run(FORWARD);

Some informations about adafruit motor shield ( this one is for version 1 motor shield ) :

To connect a motor, simply solder two wires to the terminals and then connect them to either the M1, M2, M3, or M4. Then follow these steps in your sketch

Make sure you #include <AFMotor.h>
Create the AF_DCMotor object with AF_DCMotor(motor#, frequency), to setup the motor H-bridge and latches. The constructor takes two arguments.
The first is which port the motor is connected to, 1, 2, 3 or 4.
frequency is how fast the speed controlling signal is.
For motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ, orMOTOR12_1KHZ. A high speed like 64KHz wont be audible but a low speed like 1KHz will use less power. Motors 3 & 4 are only possible to run at 1KHz and will ignore any setting given
Then you can set the speed of the motor using setSpeed(speed) where the speed ranges from 0 (stopped) to 255 (full speed). You can set the speed whenever you want.
To run the motor, call run(direction) where direction is FORWARD, BACKWARD or RELEASE. Of course, the Arduino doesn't actually know if the motor is 'forward' or 'backward', so if you want to change which way it thinks is forward, simply swap the two wires from the motor to the shield.

Copy Code

#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
motor.setSpeed(200); // set the speed to 200/255
}

void loop() {
Serial.print("tick");
motor.run(FORWARD); // turn it on going forward
delay(1000);

Serial.print("tock");
motor.run(BACKWARD); // the other way
delay(1000);
Serial.print("tack");
motor.run(RELEASE); // stopped
delay(1000);
}

AF_DCMotor motorname(portnum, freq)

This is the constructor for a DC motor. Call this constructor once for each motor in your sketch. Each motor instance must have a different name as in the example below.

Parameters:

port num - selects which channel (1-4) of the motor controller the motor will be connected to
freq - selects the PWM frequency. If no frequency is specified, 1KHz is used by default.

Frequencies for channel 1 & 2 are:

MOTOR12_64KHZ
MOTOR12_8KHZ
MOTOR12_2KHZ
MOTOR12_1KHZ

Frequencies for channel 3 & 4 are:

MOTOR34_64KHZ
MOTOR34_8KHZ
MOTOR34_1KHZ

Example:
Copy Code

AF_DCMotor motor4(4); // define motor on channel 4 with 1KHz default PWM
AF_DCMotor left_motor(1, MOTOR12_64KHZ); // define motor on channel 1 with 64KHz PWM

adafruit_products_DC_Motor_Ports.gif
Note: Higher frequencies will produce less audible hum in operation, but may result in lower torque with some motors.
setSpeed(speed)

Sets the speed of the motor.

Parameters:

speed- Valid values for 'speed' are between 0 and 255 with 0 being off and 255 as full throttle.

Example:
Note: DC Motor response is not typically linear, and so the actual RPM will not necessarily be proportional to the programmed speed.
run(cmd)

Sets the run-mode of the motor.

Parameters:

cmd - the desired run mode for the motor

Valid values for cmd are:

FORWARD - run forward (actual direction of rotation will depend on motor wiring)
BACKWARD - run backwards (rotation will be in the opposite direction from FORWARD)
RELEASE - Stop the motor. This removes power from the motor and is equivalent to setSpeed(0). The motor shield does not implement dynamic breaking, so the motor may take some time to spin down

Example:
Copy Code

motor.run(FORWARD);
delay(1000); // run forward for 1 second
motor.run(RELEASE);
delay(100); // 'coast' for 1/10 second
motor.run(BACKWARDS); // run in reverse

From this link you can see the adafruit Version 1 ( V1 ) motor shield's .h and .cpp documents ( Please check ) :

From this link you can see the adafruit Version 1 ( V2 ) motor shield's .h and .cpp documents ( Please check ) :

Sorry if my comment is so long, for 2 days I am searching non-stop really. I give everything related with adafruit motorshield version 1 and 2, the basics of this motor shield.

UKHeliBob, Would you write for me a simple adafruit motor shield ( V1 or V2 ) coding for the control the speed and direction of 1 dc motor with 1 potentiometer please ? I want to see where I do wrong. I hope that you / anyone would help me to fix this issue, thank you very much.