Page 1 of 1

10A DC Motor Driver Arduino Shield direction

PostPosted: Mon Mar 16, 2015 3:52 am
by carlosap
on the sample code you use :
// Control the motor according to the speed value.
// Positive speed value = CW,
// Negative speed value = CCW.
if (iSpeed >= 0) {
analogWrite(pinPwm, iSpeed);
digitalWrite(pinDir, LOW);
}
else {
analogWrite(pinPwm, -iSpeed);
digitalWrite(pinDir, HIGH);
}

what does the direction pin controls? do I always wave to have positive pwm with low? what if I put -ispeed with low direction?
what does actually control the direction the pas/neg value of the PWM of the pinDir: LOW/HIGH?

Re: 10A DC Motor Driver Arduino Shield direction

PostPosted: Mon Mar 16, 2015 11:54 am
by waiweng83
pinDir control the direction of the motor and the PWM value in analogWrite(pinPwm, VALUE) must be always positive.

In this example, we use a single variable "iSpeed" to control the speed and direction of the motor. If this value is positive, the pinDir is set to LOW while if it is negative, the pinDir will be set to high.

If you 12 control the pinDir directly, you can just do like this:

// Run motor clockwise.
analogWrite(pinPwm, value);
digitalWrite(pinDir, LOW);

// Run motor counter clockwise.
analogWrite(pinPwm, value);
digitalWrite(pinDir, HIGH);

Re: 10A DC Motor Driver Arduino Shield direction

PostPosted: Mon Mar 16, 2015 9:54 pm
by carlosap
Thanks. It threw me off but after your reply I got it. It passes an iSpeed negative and the -Ispeed turns it into positive..hahaha