I'm programming to TREX motor controller. Somehow I cannot make the motor go backward. However, my code is pretty much the same as the sample code in the tutorial. Could someone help me out? Thanks a lot.
The code is like below, when the inputSpeed less than 0, it should set lmdirpin and rmdirpin to 0, and therefore go backwards, however, the code doesn't work and I cannot debug it out. And I'm sure the pin numbers are right. Can any one help me to figure it out. Thanks for the help.
int motorControl(int ifForward){
// Increase or decrease speed as requested
if(ifForward){
inputSpeed += 10;
}
else{
inputSpeed -= 10;
}
// Be sure speed stays within range
if(inputSpeed > 255){
inputSpeed = 255;
}
else if(inputSpeed < -255){
inputSpeed = -255;
}
digitalWrite(lmdirpin,inputSpeed>0); // Set left motor direction, doesn't work
digitalWrite(rmdirpin,inputSpeed>0); // Set right motor direction, doesnt' work
analogWrite (lmpwmpin,abs(inputSpeed)); // set left PWM to absolute value of left speed - if brake is engaged then PWM
analogWrite (rmpwmpin,abs(inputSpeed)); // set right PWM to absolute value of right speed - if brake is engaged then
delayMicroseconds(50); // limit full power to 50uS
}