code has been ported and works on CP 3.0.3 Trinket M0
# Trinket Gemma Servo Control
# for Adafruit M0 boards
+import time
import board
import pulseio
from adafruit_motor import servo
@@ -8,12 +9,16 @@ from adafruit_motor import servo
# servo pin for the M0 boards:
pwm = pulseio.PWMOut(board.A2, duty_cycle=2 ** 15, frequency=50)
my_servo = servo.Servo(pwm)
+speed = .04 # 40ms lower value means faster movement
+max_turn = 180 # 150 degrees
while True:
- for angle in range(0,100,5)
- print(angle)
+ # move stepper max_turn degrees clockwise
+ for angle in range(0, max_turn, 1):
my_servo.angle = angle
+ time.sleep(speed)
- for angle in range(100,0,-5)
- print(angle)
+ # move stepper max_turn degrees counter clockwise
+ for angle in range(max_turn, 0, -1):
my_servo.angle = angle
+ time.sleep(speed)
