Example #1
0
        private void SetGPIOWrite2(int in3, int in4)
        {
            if (in3 == 0 || in3 == -1)
            {
                IN3.Write(GpioPinValue.Low);
            }
            if (in3 == 1)
            {
                IN3.Write(GpioPinValue.High);
            }
            if (in3 == -1)
            {
                IN3.Dispose();
            }


            if (in4 == 0 || in4 == -1)
            {
                IN4.Write(GpioPinValue.Low);
            }
            if (in4 == 1)
            {
                IN4.Write(GpioPinValue.High);
            }
            if (in4 == -1)
            {
                IN4.Dispose();
            }
        }
Example #2
0
        /// <summary>
        /// Create an instance of the ULN2003 driver (currently only supports 28BYJ step motor)
        /// </summary>
        public ULN2003(int IN1pin, int IN2pin, int IN3pin, int IN4pin, ULN2003Enums motorType = ULN2003Enums.STEP_28BYJ)
        {
            if (motorType == ULN2003Enums.Other)
            {
                IsSupported = false;
            }
            else
            {
                var gpio = GpioController.GetDefault();
                if (gpio != null)
                {
                    IN1 = gpio.OpenPin(IN1pin);
                    IN2 = gpio.OpenPin(IN2pin);
                    IN3 = gpio.OpenPin(IN3pin);
                    IN4 = gpio.OpenPin(IN4pin);

                    IN1.SetDriveMode(GpioPinDriveMode.Output);
                    IN2.SetDriveMode(GpioPinDriveMode.Output);
                    IN3.SetDriveMode(GpioPinDriveMode.Output);
                    IN4.SetDriveMode(GpioPinDriveMode.Output);

                    SetGPIOWrite(0, 0, 0, 0);

                    SetStepSequences(motorType);

                    SafeBreakMe = new SafeBreak();
                    SafeBreakMe.PropertyChanged += SafeBreakMe_PropertyChanged;

                    IsInitialized = true;
                }
            }
        }
Example #3
0
        /// <summary>
        /// Create an instance of the L298N driver (PCA9685 driver can be used as extension to have more
        /// stable PWM outputs as Windows IOT is not a real time operating system)
        /// </summary>
        /// <param name="motor1">initialize the motor1 with available pins for the driver</param>
        /// <param name="motor2">initialize the motor2 with available pins for the driver</param>
        /// <param name="pwnDriver">pwm driver to control the speed of the motor (PCA9685 chip)</param>
        public L298N(L298NMotors motor1, L298NMotors motor2, PCA9685 pwnDriver = null)
        {
            var gpio = GpioController.GetDefault();

            if (gpio != null)
            {
                GetPCA9685 = pwnDriver;

                if (GetPCA9685 != null)
                {
                    GetPCA9685.SetDesiredFrequency(60);
                }

                if (motor1 != null)
                {
                    IN1 = gpio.OpenPin(motor1.INAPin);
                    IN2 = gpio.OpenPin(motor1.INBPin);

                    IN1.SetDriveMode(GpioPinDriveMode.Output);
                    IN2.SetDriveMode(GpioPinDriveMode.Output);

                    ENA = motor1.ENPin;

                    SetGPIOWrite1(0, 0);

                    if (GetPCA9685 != null)
                    {
                        GetPCA9685.SetPulseParameters(ENA, 0);
                    }

                    Motor1Available = true;
                }

                if (motor2 != null)
                {
                    IN3 = gpio.OpenPin(motor2.INAPin);
                    IN4 = gpio.OpenPin(motor2.INBPin);

                    IN3.SetDriveMode(GpioPinDriveMode.Output);
                    IN4.SetDriveMode(GpioPinDriveMode.Output);

                    ENB = motor2.ENPin;

                    SetGPIOWrite2(0, 0);

                    if (GetPCA9685 != null)
                    {
                        GetPCA9685.SetPulseParameters(ENB, 0);
                    }

                    Motor2Available = true;
                }

                if (Motor1Available || Motor2Available)
                {
                    IsInitialized = true;
                }
            }
        }