User Manual

DC motors are controlled by 4 PWM output pins, the 4 PWM pins let you control speed
and
direction. And we'll use our
adafruit_motor library to help us manage the throttle (speed) and direction for us, making it very easy to control motors
Note that each DC motor is a little different, so just because you have two at the same throttle does not mean they'll
rotate at the
exact
same speed! Some tweaking may be required
Import Libraries
We start by importing the libraries that we need to have time delays ( import time ) and then the main crickit python
library that will make it super easy to talk to the motors and sensors on crickit ( from adafruit_crickit import crickit )
The crickit object represents the motors and servos available for control. The motors are available on the sub-objects
named dc_motor_1 and dc_motor_2
The two wires of the DC motor can be plugged in either way into each Crickit Motor port. If the motor spins
the opposite way from what you want to call 'forward', just flip the wires!
import time
from adafruit_crickit import crickit
print("Dual motor demo!")
# make two variables for the motors to make code shorter to type
motor_1 = crickit.dc_motor_1
motor_2 = crickit.dc_motor_2
while True:
motor_1.throttle = 1 # full speed forward
motor_2.throttle = -1 # full speed backward
time.sleep(1)
motor_1.throttle = 0.5 # half speed forward
motor_2.throttle = -0.5 # half speed backward
time.sleep(1)
motor_1.throttle = 0 # stopped
motor_2.throttle = 0 # also stopped
time.sleep(1)
motor_1.throttle = -0.5 # half speed backward
motor_2.throttle = 0.5 # half speed forward
time.sleep(1)
motor_1.throttle = -1 # full speed backward
motor_2.throttle = 1 # full speed forward
time.sleep(1)
motor_1.throttle = 0 # stopped
motor_2.throttle = 0 # also stopped
time.sleep(0.5)
# and repeat!
© Adafruit Industries
https://learn.adafruit.com/adafruit-crickit-creative-robotic-interactive-
construction-kit
Page 98 of 201