Up GoPiGo3/Servo.py 作成: 2021-05-19
更新: 2021-05-19


    $ cat ~/Dexter/GoPiGo3/Software/Python/Examples/Servo.py #!/usr/bin/env python # # https://www.dexterindustries.com/GoPiGo/ # https://github.com/DexterInd/GoPiGo3 # # Copyright (c) 2017 Dexter Industries # Released under the MIT license (http://choosealicense.com/licenses/mit/). # For more information see https://github.com/DexterInd/GoPiGo3/blob/master/LICENSE.md # # This code is an example for controlling the GoPiGo3 Servos # # Results: When you run this program, the GoPiGo3 Servos will rotate back and forth. from __future__ import print_function # use python 3 syntax but make it compatible with python 2 from __future__ import division # '' import time # import the time library for the sleep function import gopigo3 # import the GoPiGo3 drivers GPG = gopigo3.GoPiGo3() # Create an instance of the GoPiGo3 class. GPG will be the GoPiGo3 object. try: while True: for i in range(1000, 2001): # count from 1000 to 2000 GPG.set_servo(GPG.SERVO_1, i) GPG.set_servo(GPG.SERVO_2, 3000-i) time.sleep(0.001) for i in range(1000, 2001): # count from 1000 to 2000 GPG.set_servo(GPG.SERVO_2, i) GPG.set_servo(GPG.SERVO_1, 3000-i) time.sleep(0.001) except KeyboardInterrupt: # except the program gets interrupted by Ctrl+C on the keyboard. GPG.reset_all() # Unconfigure the sensors, disable the motors, and restore the LED to the control of the GoPiGo3 firmware.