Created
June 10, 2015 16:02
-
-
Save MrYsLab/7064e9e27378432a1812 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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