Skip to content

Instantly share code, notes, and snippets.

@MrYsLab
Created June 10, 2015 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrYsLab/7064e9e27378432a1812 to your computer and use it in GitHub Desktop.
Save MrYsLab/7064e9e27378432a1812 to your computer and use it in GitHub Desktop.
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment