0% found this document useful (0 votes)
23 views

Motor Test Code

Uploaded by

Waqas Salman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Motor Test Code

Uploaded by

Waqas Salman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <AFMotor.

h>
AF_DCMotor motor_1(1);
AF_DCMotor motor_2(2);
void setup()
{
//Set initial speed of the motor & stop
motor_1.setSpeed(300);
motor_1.run(RELEASE);
motor_2.setSpeed(300);
motor_2.run(RELEASE);
}
void loop()
{
uint8_t i;
// Turn on motor
motor_1.run(FORWARD);
motor_2.run(FORWARD);
// Accelerate from zero to maximum speed
for (i=0; i<255; i++)
{
motor_1.setSpeed(i);
motor_2.setSpeed(i);
delay(5);
}
// Decelerate from maximum speed to zero
for (i=255; i!=0; i--)
{
motor_1.setSpeed(i);
motor_2.setSpeed(i);
delay(5);
}
// Now change motor direction
motor_1.run(BACKWARD);
motor_2.run(BACKWARD);
// Accelerate from zero to maximum speed
for (i=0; i<255; i++)
{
motor_1.setSpeed(i);
motor_2.setSpeed(i);
delay(5);
}
// Decelerate from maximum speed to zero
for (i=255; i!=0; i--)
{
motor_1.setSpeed(i);
motor_2.setSpeed(i);

delay(5);
}
// Now turn off motor
motor_1.run(RELEASE);
motor_2.run(RELEASE);

delay(100);
}

You might also like