Skip to content

Commit e333870

Browse files
authored
Merge pull request #5 from dhalbert/rework_api
Rework api
2 parents bcf1c0b + 4b00e4c commit e333870

16 files changed

+464
-556
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ install:
2424
- pip install -r requirements.txt
2525
- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme
2626
script:
27-
- pylint adafruit_crickit/*.py
27+
- pylint adafruit_crickit.py
2828
- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace
2929
examples/*.py)
3030
- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-crickit --library_location

README.rst

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,54 +37,46 @@ In most cases you just need a couple of imports.
3737
3838
# This is a mock example showing typical usage of the library for each kind of device.
3939
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
5041
5142
# Add this import if using stepper motors.
5243
# It will expose constants saying how to step: stepper.FORWARD, stepper.BACKWARD, etc.
5344
from adafruit_motor import stepper
5445
55-
servo1 = crickit.servo(SERVO1)
56-
servo1.angle = 90
46+
# Set servo 1 to 90 degrees
47+
crickit.servo_1.angle = 90
5748
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)
6052
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
6356
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
6659
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
6962
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
7365
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")
8068
8169
# 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)
8471
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))
8880
8981
9082
Contributing

0 commit comments

Comments
 (0)