Make sure you include <AFMotor.h>
means you need to do this:
#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.
You can have no more than 4 motors controlled be the shield. The first argument defines which set of pins the motor is actually connected to. This should be pretty obvious from where you connected the wires to the shield.
The motor control library sends signals to the motor, every now and then. How often it does that is called the frequency.
For motors 1 and 2 you can choose MOTOR12_64KHZ, MOTOR12_8KHZ, MOTOR12_2KHZ, or MOTOR12_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
If you understand what frequency is, and what it means, this statement should be pretty simple. Higher frequency input means the motor's on and off times are shorter. The very short times produce noise, but the frequency of that noise is too high for humans to hear. The tradeoff is that more power is consumed switching the motor on and off that fast.
What you need to decide is how much noise is too much. If the motors are moving a gasoline engined powered lawnmower around, you won't be able to hear the motor-induced noise over the gasoline engine noise, no matter how loud it is.
If the motors are moving a record player turntable, noise will be a problem.
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.
This should be pretty obvious. You can control how fast the motor turns. The range of values is defined here, and what that range means.
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.
This should be pretty obvious, too. If not, experiment with different values, and observe the affects.