Hi,
I am using an arduino mega with a seeedstudio motor controller version 1.2 (Motor_Shield_V1.0).
The trouble I am having is that I am mapping a joystick from 510 - 1023 to 0 - 255 for forward and 506 - 0 to 0 - 255 for backward. Backward works as expected, it speeds up the motor in reverse as I pull back on the joystick and slows down as I bring it back up. But forward also makes the motor go in reverse and starts out fast then slows down as I push the joystick up. I hope you can help me make the forward function go forward and start slow and speed up as I push the joystick up.
Thanks
void forward()
{
fspead = map(joystick[1], 510, 1023, 0, 255);
analogWrite(speedpinA,fspead);//input a simulation value to set the speed
analogWrite(speedpinB,fspead);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
}
void backward()//
{
bspead = map(joystick[1], 506, 0, 0, 255);
analogWrite(speedpinA,bspead);//input a simulation value to set the speed
analogWrite(speedpinB,bspead);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
else if (joystick[1] <= 505 && joystick[0] >=509 && joystick[0] <=513)
{
backward();
if (joystick[1] < 510 && joystick[1] > 502 && joystick[0] >=510 && joystick[0] <=509)
{
stop();
}
}
else if (joystick[1] >= 510 && joystick[0] >=510 && joystick[0] <=509)
{
forward();
if (joystick[1] < 510 && joystick[1] > 502 && joystick[0] >=510 && joystick[0] <=509)
{
stop();
}
}