Example #1
0
        /// <summary>
        /// Initializes four pins for motor driver
        /// </summary>
        /// <param name="Pin_MotorLeft_A">Left motor's Pin A.</param>
        /// <param name="Pin_MotorLeft_B">Left motor's Pin B.</param>
        /// <param name="Pin_MotorRight_A">Right motor's Pin A.</param>
        /// <param name="Pin_MotorRight_B">Right motor's Pin B.</param>
        public static void InitializePins(AvailableGpioPin Pin_MotorLeft_A, AvailableGpioPin Pin_MotorLeft_B, AvailableGpioPin Pin_MotorRight_A, AvailableGpioPin Pin_MotorRight_B)
        {
            // Initialize Gpio Controller
            GpioController MyGpioConroller = GpioController.GetDefault();

            // If GpioPins are not null then make them first null to release old pins.
            // Check only one pin against null and if it is not then null all.
            if (MotorLeft_A != null)
            {
                MotorLeft_A  = null;
                MotorLeft_B  = null;
                MotorRight_A = null;
                MotorRight_B = null;
            }

            // Initialize Pins
            MotorLeft_A = MyGpioConroller.OpenPin((int)Pin_MotorLeft_A);
            MotorLeft_B = MyGpioConroller.OpenPin((int)Pin_MotorLeft_B);

            MotorRight_A = MyGpioConroller.OpenPin((int)Pin_MotorRight_A);
            MotorRight_B = MyGpioConroller.OpenPin((int)Pin_MotorRight_B);

            // Set Drive Mode
            MotorLeft_A.SetDriveMode(GpioPinDriveMode.Output);
            MotorLeft_B.SetDriveMode(GpioPinDriveMode.Output);
            MotorRight_A.SetDriveMode(GpioPinDriveMode.Output);
            MotorRight_B.SetDriveMode(GpioPinDriveMode.Output);

            // Set Current State
            _CurrentState = State.Stopped;
        }
Example #2
0
        public static void Stop()
        {
            // Return if pins are not initialized
            if (MotorLeft_A == null)
            {
                return;
            }

            // Left Motor
            MotorLeft_A.Write(GpioPinValue.Low);
            MotorLeft_B.Write(GpioPinValue.Low);

            // Right Motor
            MotorRight_A.Write(GpioPinValue.Low);
            MotorRight_B.Write(GpioPinValue.Low);

            // Set current state
            _CurrentState = State.Stopped;
        }
Example #3
0
        public static void MoveReverse()
        {
            // Return if pins are not initialized
            if (MotorLeft_A == null)
            {
                return;
            }

            // Left Motor
            MotorLeft_A.Write(GpioPinValue.High);
            MotorLeft_B.Write(GpioPinValue.Low);

            // Right Motor
            MotorRight_A.Write(GpioPinValue.High);
            MotorRight_B.Write(GpioPinValue.Low);

            // Set current state
            _CurrentState = State.MovingReverse;
        }