/ examples / crickit_multi_example.py
crickit_multi_example.py
 1  # This is a mock example showing typical usage of the library for each kind of device.
 2  
 3  # Add this import if using stepper motors.
 4  # It will expose constants saying how to step: stepper.FORWARD, stepper.BACKWARD, etc.
 5  from adafruit_motor import stepper
 6  
 7  from adafruit_crickit import crickit
 8  
 9  # Set servo 1 to 90 degrees
10  crickit.servo_1.angle = 90
11  
12  # Change servo settings.
13  crickit.servo_1.actuation_range = 135
14  crickit.servo_1.set_pulse_width_range(min_pulse=850, max_pulse=2100)
15  
16  # You can assign a device to a variable to get a shorter name.
17  servo_2 = crickit.servo_2
18  servo_2.throttle = 0
19  
20  # Run a continous servo on Servo 2 backwards at half speed.
21  crickit.continuous_servo_2.throttle = -0.5
22  
23  # Run the motor on Motor 1 terminals at half speed.
24  crickit.dc_motor_1.throttle = 0.5
25  
26  # Set Drive 1 terminal to 3/4 strength.
27  crickit.drive_1.fraction = 0.75
28  
29  if crickit.touch_1.value:
30      print("Touched terminal Touch 1")
31  
32  # A single stepper motor uses up all the motor terminals.
33  crickit.stepper_motor.onestep(direction=stepper.FORWARD)
34  
35  # You can also use the Drive terminals for a stepper motor
36  crickit.drive_stepper_motor.onestep(direction=stepper.BACKWARD)
37  
38  # Note: On CPX Crickit, NeoPixel pin is normally connected to A1, not to seesaw,
39  # so this part of the demo cannot control the NeoPixel terminal.
40  # Strip or ring of 8 NeoPixels
41  crickit.init_neopixel(8)
42  crickit.neopixel.fill((100, 100, 100))