Click or drag to resize
MotorHat2348 Class
Driver class for the Adafruit DC & Stepper Motor HAT for Raspberry Pi.
Inheritance Hierarchy
SystemObject
  Adafruit.IoT.DevicesMotorHat2348

Namespace:  Adafruit.IoT.Devices
Assembly:  Adafruit.IoT (in Adafruit.IoT.dll) Version: 1.0.6.0 (1.0.6.0)
Syntax
public sealed class MotorHat2348 : IClosable, 
	IStringable

The MotorHat2348 type exposes the following members.

Constructors
  NameDescription
Public methodMotorHat2348
Initializes a new instance of the MotorHat2348 class with the default I2C address and PWM frequency.
Public methodMotorHat2348(Byte)
Initializes a new instance of the MotorHat2348 class with the specified I2C address and default PWM frequency.
Public methodMotorHat2348(Byte, Double)
Initializes a new instance of the MotorHat2348 class with the specified I2C address and PWM frequency.
Top
Properties
  NameDescription
Public propertyMotors
Gets all motors created to this MotorHat2348.
Public propertyPwmPins
Gets all auxiliary PWM pins created to this MotorHat2348.
Top
Methods
  NameDescription
Public methodClose
Public methodCreateDCMotor
Creates a PwmDCMotor object for the specified channel and adds it to the list of Motors.
Public methodCreatePwm
Creates a PwmPin for the specified channel.
Public methodCreateStepperMotor
Creates a PwmStepperMotor object for the specified channels and adds it to the list of Motors.
Public methodEquals (Inherited from Object.)
Public methodGetHashCode (Inherited from Object.)
Public methodGetType (Inherited from Object.)
Public methodToString (Inherited from Object.)
Top
Remarks

See the Adafruit DC & Stepper Motor HAT for Raspberry Pi – Mini Kit here

To use this class:

using Adafruit.IoT.Devices;
using Adafruit.IoT.Motors;
using System;
using System.Threading.Tasks;
using Windows.Devices.Pwm;

namespace Adafruit.IoT
{
    internal class Examples
    {
        public async void Example1()
        {
            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.SetActiveDutyCyclePercentage(0.5);
            pwm.Start();

            // 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();
        }
    }
 }

See Also