from ev3dev2.motor import MediumMotor from time import sleep # Initialize motor on port C motor = MediumMotor('outC') # Rotate the motor 90 degrees motor.on_for_degrees(speed=50, degrees=90) # Reset the motor position to zero motor.reset() # Rotate the motor back to its original position motor.on_for_degrees(speed=50, degrees=-90)
from ev3dev2.motor import MediumMotor from time import sleep # Initialize motor on port D motor = MediumMotor('outD') # Rotate the motor continuously motor.on(speed=50) # Wait for 5 seconds sleep(5) # Stop the motor and reset its position to zero motor.off() motor.reset()In this example, we initialize a MediumMotor object on port D and rotate the motor continuously at a speed of 50. After 5 seconds, we stop the motor and reset its position to zero.