Exemple #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();
        }
Exemple #2
0
 public MainPage()
 {
     this.InitializeComponent();
     mh      = new MotorHat2348(0x60);
     stepper = mh.CreateStepperMotor(1, 2, 200);
     stepper.SetSpeed(60);
     stepper.PowerFactor = 0.25;
 }
Exemple #3
0
 private void button1_Click(object sender, RoutedEventArgs e)
 {
     if (mh != null)
     {
         mh.Dispose();
         mh = null;
     }
     Application.Current.Exit();
 }
Exemple #4
0
        public Robot()
        {
            _controller = new MotorHat2348();

            _leftMotor = _controller.CreateDCMotor(1);
            _leftMotor.SetSpeed(60);

            _rightMotor = _controller.CreateDCMotor(2);
            _rightMotor.SetSpeed(60);
        }
Exemple #5
0
        public async void DCMotorExample()
        {
            var mh    = new MotorHat2348(0x60);
            var motor = mh.CreateDCMotor(3);

            int    incrementDelay = 50; // milliseconds
            double speedIncrement = 0.01;

            while (true)
            {
                motor.Run(Direction.Forward);

                Debug.WriteLine("Forward - Speed Up!");
                for (double i = 0; i < 1; i += speedIncrement)
                {
                    motor.SetSpeed(i);
                    await Task.Delay(incrementDelay);
                }
                Debug.WriteLine("Forward - Slow Down!");
                for (double i = 1; i > 0; i -= speedIncrement)
                {
                    motor.SetSpeed(i);
                    await Task.Delay(incrementDelay);
                }

                motor.Run(Direction.Backward);

                Debug.WriteLine("Backward - Speed Up!");
                for (double i = 0; i < 1; i += speedIncrement)
                {
                    motor.SetSpeed(i);
                    await Task.Delay(incrementDelay);
                }
                Debug.WriteLine("Backward - Slow Down!");
                for (double i = 1; i > 0; i -= speedIncrement)
                {
                    motor.SetSpeed(i);
                    await Task.Delay(incrementDelay);
                }
                motor.Run(Direction.Release);
                Debug.WriteLine("reapeat!");
            }
        }
Exemple #6
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();
        }