public void Motordirection(App.DIRECTION d) { if (!bStop) { SetMotorDirection(d); } }
private void SetMotorDirection(App.DIRECTION d) { //first stop the motors, change direction and then start the motors pwmMotorLeft.Stop(); pwmMotorRight.Stop(); switch (d) { case App.DIRECTION.FORWARD: //Both Motors in the same direction - Forward MotorLeftNegative.Write(GpioPinValue.Low); MotorLeftPositive.Write(GpioPinValue.High); MotorRightNegative.Write(GpioPinValue.Low); MotorRightPositive.Write(GpioPinValue.High); break; case App.DIRECTION.REVERSE: //Both Motors in the same direction but Reverse MotorLeftNegative.Write(GpioPinValue.High); MotorLeftPositive.Write(GpioPinValue.Low); MotorRightNegative.Write(GpioPinValue.High); MotorRightPositive.Write(GpioPinValue.Low); break; case App.DIRECTION.LEFT: //One of the Motor is in the reverse, while the other forward - Friction turn MotorLeftNegative.Write(GpioPinValue.Low); MotorLeftPositive.Write(GpioPinValue.High); //Left Motor Forward MotorRightNegative.Write(GpioPinValue.High); MotorRightPositive.Write(GpioPinValue.Low); //Right Motor Reverse break; case App.DIRECTION.RIGHT: //One of the Motor is in the reverse, while the other forward - Friction turn MotorLeftNegative.Write(GpioPinValue.High); MotorLeftPositive.Write(GpioPinValue.Low); MotorRightNegative.Write(GpioPinValue.Low); MotorRightPositive.Write(GpioPinValue.High); break; } pwmMotorLeft.Start(); pwmMotorRight.Start(); }