Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- from inventor import Inventor2040W, MOTOR_A
- """
- Demonstrates how to control a motor on Inventor 2040 W
- Rotate 180 degrees, wait and rotate back to starting position
- ********** HALT with User Button ***********
- Tony Goodhew 28 March 2023
- """
- # Create a new Inventor2040W
- board = Inventor2040W()
- # Access the motor from Inventor and enable it
- m = board.motors[MOTOR_A]
- m.enable()
- sp = 0.2
- delay = 1
- angle = board.encoders[0].degrees()
- while not board.switch_pressed():
- m.speed(sp)
- while angle < 180:
- angle = board.encoders[0].degrees()
- m.speed(0)
- print(board.encoders[0].degrees())
- time.sleep(delay)
- angle = board.encoders[0].degrees()
- m.speed(-sp)
- while angle > 0:
- angle = board.encoders[0].degrees()
- m.speed(0)
- print(board.encoders[0].degrees())
- time.sleep(delay)
- # Disable the motor
- m.disable()
Advertisement
Comments
-
- Written for Pimoroni Inventor 2040 with motors fitted with encoders. MicroPython
Add Comment
Please, Sign In to add comment
Advertisement