User Manual

Code!
Save to your CPX as code.py and press the CPX buttons to move the pulley up and down. Capacitive touch pads #1
and #4 twist the servo and then the switch enables and disables the electromagnet.
The most interesting part is smooth_move which is our gentle servo movement helper, it will carefully move the servo
rather than jostling it and the magnet which would possibly cause the balls to fall.
import time
from busio import I2C
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import motor, servo
from digitalio import DigitalInOut, Direction, Pull
import board
print("Mag Neat-o!")
# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)
# Create one motor on seesaw PWM pins 22 & 23
motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23))
# Create another motor on seesaw PWM pins 19 & 18
motor_b = motor.DCMotor(PWMOut(seesaw, 19), PWMOut(seesaw, 18))
# Create servo object
pwm = PWMOut(seesaw, 17) # Servo 1 is on s.s. pin 17
pwm.frequency = 50 # Servos like 50 Hz signals
my_servo = servo.Servo(pwm) # Create my_servo with pwm signa
my_servo.angle = 90
def smooth_move(start, stop, num_steps):
return [(start + (stop-start)*i/num_steps) for i in range(num_steps)]
buttona = DigitalInOut(board.BUTTON_A)
buttona.direction = Direction.INPUT
buttona.pull = Pull.DOWN
buttonb = DigitalInOut(board.BUTTON_B)
buttonb.direction = Direction.INPUT
buttonb.pull = Pull.DOWN
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
last_buttona = buttona.value
last_buttonb = buttonb.value
last_switch = switch.value
last_touch1 = False
last_touch4 = False
while True:
touch_vals = (seesaw.touch_read(0), seesaw.touch_read(3))
© Adafruit Industries
https://learn.adafruit.com/adafruit-crickit-creative-robotic-interactive-
construction-kit
Page 158 of 201