Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import time
  2. import sys
  3. import signal
  4.  
  5. from PyMata.pymata import PyMata
  6.  
  7.  
  8. SERVO_MOTOR = 5 # servo attached to this pin
  9.  
  10. # create a PyMata instance
  11. board = PyMata("/dev/ttyACM0")
  12.  
  13.  
  14. def signal_handler(sig, frame):
  15. print('You pressed Ctrl+C!!!!')
  16. if board is not None:
  17. board.reset()
  18. sys.exit(0)
  19.  
  20. signal.signal(signal.SIGINT, signal_handler)
  21. # control the servo - note that you don't need to set pin mode
  22. # configure the servo
  23. board.servo_config(SERVO_MOTOR)
  24.  
  25. for x in range(0, 20):
  26.  
  27. # move the servo to 20 degrees
  28. board.analog_write(SERVO_MOTOR, 20)
  29. time.sleep(1)
  30.  
  31. # move the servo to 100 degrees
  32. board.analog_write(SERVO_MOTOR, 100)
  33. time.sleep(1)
  34.  
  35. # move the servo to 20 degrees
  36. board.analog_write(SERVO_MOTOR, 20)
  37.  
  38. # close the interface down cleanly
  39. board.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement