Exemplo n.º 1
0
        public async void StepperMotorExample()
        {
            MotorHat2348    mh      = null;
            PwmStepperMotor stepper = null;
            PwmPin          pwm     = null;

            if (mh == null)
            {
                // Create a driver object for the HAT at address 0x60
                mh = new MotorHat2348(0x60);
                // Create a stepper motor object at the specified ports and steps per rev
                stepper = mh.CreateStepperMotor(1, 2, 200);
                // Create a PwmPin object at one of the auxiliary PWMs on the HAT
                pwm = mh.CreatePwm(1);
            }

            // step 200 full steps in the forward direction using half stepping (so 400 steps total) at 30 rpm
            stepper.SetSpeed(30);
            await stepper.StepAsync(200, Direction.Forward, SteppingStyle.Half);

            // Activate the pin and set it to 50% duty cycle
            pwm.Start();
            pwm.SetActiveDutyCyclePercentage(0.5);

            // for demonstration purposes we will wait 10 seconds to observe the PWM and motor operation.
            await Task.Delay(10000);

            // Stop the auxiliary PWM pin
            pwm.Stop();

            // Dispose of the MotorHat and free all its resources
            mh.Dispose();
        }
Exemplo n.º 2
0
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            deferral = taskInstance.GetDeferral();

            var mh = new MotorHat2348(0x60);  //this is I2C address?

            var motor1 = mh.CreateDCMotor(1);

            motor1.SetSpeed(30);
            motor1.Run(Direction.Forward);

            var motor2 = mh.CreateDCMotor(2);

            motor2.SetSpeed(30);
            motor2.Run(Direction.Forward);

            //var motor3 = mh.CreateDCMotor(3);
            //motor3.SetSpeed(30);
            //motor3.Run(Direction.Forward);

            //var motor4 = mh.CreateDCMotor(4);
            //motor4.SetSpeed(30);
            //motor4.Run(Direction.Forward);


            var pwm = mh.CreatePwm(1);

            pwm.Start();


            var x = 9;

            pwm.Stop();


            //var wait = Task.Delay(5000);
            //while (!wait.IsCompleted)
            //{
            //}
            //motor1.SetSpeed(0);
            //motor1.Dispose();
        }