#include <AFMotor.h>
AF_DCMotor motor(1, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
int pot = A1; //puerto analogo del motor
int valpot =0; //declaracion del valor del puerto
// se ejecuta 1 sola vez, al iniciar el programa
void setup() {
pinMode(pot, INPUT);
}
// se repite infinitamente mientras el arduino tenga corriente
void loop() {
valpot= analogRead(pot);
if( valpot >= 0 && valpot <401)
{
int indice = map(valpot,400,0,0,255 );
motor.setSpeed(indice); // set the speed to 200/255
motor.run(BACKWARD);
}
else if(valpot > 400 && valpot < 625)
{
int indice = map(valpot,401,624,0,255 );
motor.run(RELEASE); // stopped
// the other way
}
else if(valpot > 624 && valpot < 1024)
{
int indice = map(valpot,625,1023,0,255 );
motor.run(FORWARD);
}
}