Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import sys
- import signal
- from PyMata.pymata import PyMata
- SERVO_MOTOR = 5 # servo attached to this pin
- # create a PyMata instance
- board = PyMata("/dev/ttyACM0")
- def signal_handler(sig, frame):
- print('You pressed Ctrl+C!!!!')
- if board is not None:
- board.reset()
- sys.exit(0)
- signal.signal(signal.SIGINT, signal_handler)
- # control the servo - note that you don't need to set pin mode
- # configure the servo
- board.servo_config(SERVO_MOTOR)
- for x in range(0, 20):
- # move the servo to 20 degrees
- board.analog_write(SERVO_MOTOR, 20)
- time.sleep(1)
- # move the servo to 100 degrees
- board.analog_write(SERVO_MOTOR, 100)
- time.sleep(1)
- # move the servo to 20 degrees
- board.analog_write(SERVO_MOTOR, 20)
- # close the interface down cleanly
- board.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement