Advertisement
TonyGo

Untitled

Mar 28th, 2023
473
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | Source Code | 0 0
  1. import time
  2. from inventor import Inventor2040W, MOTOR_A
  3.  
  4. """
  5.   Demonstrates how to control a motor on Inventor 2040 W
  6. Rotate 180 degrees, wait and rotate back to starting position
  7.  
  8.    ********** HALT with User Button ***********
  9.    
  10.             Tony Goodhew 28 March 2023
  11. """
  12.  
  13. # Create a new Inventor2040W
  14. board = Inventor2040W()
  15.  
  16. # Access the motor from Inventor and enable it
  17. m = board.motors[MOTOR_A]
  18. m.enable()
  19.  
  20. sp = 0.2
  21. delay = 1
  22. angle = board.encoders[0].degrees()
  23.  
  24. while not board.switch_pressed():
  25.     m.speed(sp)
  26.     while angle < 180:
  27.         angle = board.encoders[0].degrees()
  28.     m.speed(0)
  29.     print(board.encoders[0].degrees())
  30.     time.sleep(delay)
  31.     angle = board.encoders[0].degrees()
  32.     m.speed(-sp)
  33.     while angle > 0:
  34.         angle = board.encoders[0].degrees()
  35.     m.speed(0)
  36.     print(board.encoders[0].degrees())
  37.     time.sleep(delay)
  38.  
  39. # Disable the motor
  40. m.disable()
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement