@@ -37,54 +37,46 @@ In most cases you just need a couple of imports.
37
37
38
38
# This is a mock example showing typical usage of the library for each kind of device.
39
39
40
- # crickit is a singleton object
41
- from adafruit_crickit.crickit import crickit
42
-
43
- # Terminals have simple names like SIGNAL1, SERVO2, TOUCH3, MOTOR1A, NEOPIXEL,
44
- # CPX_DRIVE1, and FEATHER_DRIVE2.
45
- # Because the Drive terminals are numbered in reverse on the CPX Crickit vs the FeatherWing Crickit,
46
- # there are separate DRIVE names for CPX and FeatherWing Drive terminals.
47
- from adafruit_crickit.terminals import (SERVO1,
48
- MOTOR1A, MOTOR1B, MOTOR2A, MOTOR2B,
49
- CPX_DRIVE1, NEOPIXEL, SIGNAL1, SIGNAL2, TOUCH1)
40
+ from adafruit_crickit import crickit
50
41
51
42
# Add this import if using stepper motors.
52
43
# It will expose constants saying how to step: stepper.FORWARD, stepper.BACKWARD, etc.
53
44
from adafruit_motor import stepper
54
45
55
- servo1 = crickit. servo(SERVO1)
56
- servo1 .angle = 90
46
+ # Set servo 1 to 90 degrees
47
+ crickit.servo_1 .angle = 90
57
48
58
- cservo1 = crickit.continuous_servo(SERVO1)
59
- cservo1.throttle = -0.5
49
+ # Change servo settings.
50
+ crickit.servo_1.actuation_range = 135
51
+ crickit.servo_1.set_pulse_widths(min_pulse=850, max_pulse=2100)
60
52
61
- motor = crickit.dc_motor(MOTOR1A, MOTOR1B)
62
- motor.throttle = 0.5
53
+ # You can assign a device to a variable to get a shorter name.
54
+ servo_2 = crickit.servo_2
55
+ servo_2.throttle = 0
63
56
64
- drive1 = crickit.pwm_out(CPX_DRIVE1)
65
- drive1.fraction = 1.0
57
+ # Run a continous servo on Servo 2 backwards at half speed.
58
+ crickit.continuous_servo_2.throttle = -0.5
66
59
67
- # Note: On CPX Crickit, NeoPixel pin is normally connected to A1, not to seesaw,
68
- # so this demo would not control the NeoPixel terminal.
60
+ # Run the motor on Motor 1 terminals at half speed.
61
+ crickit.dc_motor_1.throttle = 0.5
69
62
70
- # Strip or ring of 8 NeoPixels
71
- neopixels = crickit.neopixel(NEOPIXEL, 8)
72
- neopixels.fill((100, 100, 100))
63
+ # Set Drive 1 terminal to 3/4 strength.
64
+ crickit.drive_1.fraction = 0.75
73
65
74
- # Write Signal terminal 1 and read Signal terminal 2.
75
- ss = crickit.seesaw
76
- ss.pin_mode(SIGNAL1, ss.OUTPUT)
77
- ss.pin_mode(SIGNAL2, ss.INPUT)
78
- ss.digital_write(SIGNAL1, True)
79
- print(ss.digital_read(SIGNAL2))
66
+ if crickit.touch_1.value:
67
+ print("Touched terminal Touch 1")
80
68
81
69
# A single stepper motor uses up all the motor terminals.
82
- stepper_motor = crickit.stepper_motor(MOTOR1A, MOTOR1B, MOTOR2A, MOTOR2B)
83
- stepper_motor.onestep(direction=stepper.FORWARD)
70
+ crickit.stepper_motor.onestep(direction=stepper.FORWARD)
84
71
85
- touch1 = crickit.touch(TOUCH1)
86
- if touch1.value:
87
- print("Touched terminal Touch 1")
72
+ # You can also use the Drive terminals for a stepper motor
73
+ crickit.drive_stepper_motor.onestep(direction=stepper.BACKWARD)
74
+
75
+ # Note: On CPX Crickit, NeoPixel pin is normally connected to A1, not to seesaw,
76
+ # so this part of the demo cannot control the NeoPixel terminal.
77
+ # Strip or ring of 8 NeoPixels
78
+ crickit.init_neopixel(8)
79
+ crickit.neopixel.fill((100, 100, 100))
88
80
89
81
90
82
Contributing
0 commit comments