Arduino motor shield sketch problems

Hello, i bought a arduino motor shield and i have a few questions concerning the sketch.

Here it is:

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, 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
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.
#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);
}

Can someone please explain to me the first paragraph in a more detailed manner (for beginners).
Thanks

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.

Thanks! That was very helpful! :)

I got an error message:

‘AF_DCMotor’ does not name a type

Now what’s that supposed to mean? :~ Thanks!

It probably means the compiler can't find the library containing AF_DCMotor. Have you downloaded it? If you have, what have you done with it?

Which version of the IDE are you using?

1: I don't think so... where can i get it? 2: Version 0023 (that's what's written on the top left of the screen)

Have you definitely got an Adafruit motor shield?

where can i get it?

From LadyAda's site: http://www.ladyada.net/make/mshield/

Motor shield: http://www.ladyada.net/make/mshield/index.html

There's a download link on that page.

Now the previous code doesn't want to erase :0!? What do i do?????????????? Thanks

Now the previous code doesn't want to erase

What does this mean? Are you referring to the previous hex file on the Arduino?

yes. the last one was the blink sketch

I fixed it. Thanks everybody!! :)