from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_StepperMotor # create a motor hat object mh = Adafruit_MotorHAT(addr=0x60) # create a stepper motor object motor = mh.getStepper(200, 1) # set motor speed and direction motor.setSpeed(100) motor.step(200, Adafruit_MotorHAT.FORWARD, Adafruit_MotorHAT.SINGLE)
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor # create a motor hat object mh = Adafruit_MotorHAT(addr=0x60) # create a DC motor object motor = mh.getMotor(1) # set motor speed and direction motor.setSpeed(100) motor.run(Adafruit_MotorHAT.FORWARD)This code example uses the `getMotor()` method to create a DCMotor object, which represents a DC motor connected to the Motor HAT. The `setSpeed()` method is used to set the speed of the motor, and the `run()` method is used to start the motor in the specified direction. The Adafruit_MotorHAT package library is a Python package developed by Adafruit Industries. It provides a simple and easy-to-use interface for controlling stepper motors and DC motors using the Adafruit Motor HAT.