Skip to content

Commit

Permalink
update README with multi-example
Browse files Browse the repository at this point in the history
  • Loading branch information
dhalbert committed Jun 24, 2018
1 parent 524f138 commit 1824e9c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
53 changes: 52 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,58 @@ This is easily achieved by downloading
Usage Example
=============

.. todo:: Add a quick, simple example. It and other examples should live in the examples folder and be included in docs/examples.rst.
This examples shows how to control all the devices supported by the library.
In most cases you just need a couple of imports.

.. code-block :: python
# This is a mock example showing typical usage of the library for each kind of device.
# crickit is a singleton object
from adafruit_crickit.crickit import crickit
# Terminals have simple names like SIGNAL1, SERVO2, TOUCH3, MOTOR1A, NEOPIXEL, CPX_DRIVE1, FEATHER_DRIVE2
# Because the Drive terminals are numbered in reverse on the CPX Crickit vs the FeatherWing Crickit,
# there are separate DRIVE names for CPX and FeatherWing Drive terminals.
from adafruit_crickit.terminals import *
# Add this import if using stepper motors.
# It will expose constants saying how to step: stepper.FORWARD, stepper.BACKWARD, etc.
from adafruit_motor import stepper
servo1 = crickit.servo(SERVO1)
servo1.angle = 90
cservo1 = crickit.continuous_servo(SERVO1)
cservo1.throttle = -0.5
motor = crickit.dc_motor(MOTOR1A, MOTOR1B)
motor.throttle = 0.5
drive1 = crickit.pwm_out(CPX_DRIVE1)
drive1.fraction = 1.0
# Note: On CPX Crickit, NeoPixel pin is normally connected to A1, not to seesaw,
# so this demo would not control the NeoPixel terminal.
# Strip or ring of 8 NeoPixels
neopixels = crickit.neopixel(NEOPIXEL, 8)
neopixels.fill((100, 100, 100))
# Write Signal terminal 1 and read Signal terminal 2.
ss = crickit.seesaw
ss.pin_mode(SIGNAL1, ss.OUTPUT)
ss.pin_mode(SIGNAL2, ss.INPUT)
ss.digital_write(SIGNAL1, True)
print(ss.digital_read(SIGNAL2))
# A single stepper motor uses up all the motor terminals.
stepper_motor = crickit.stepper_motor(MOTOR1A, MOTOR1B, MOTOR2A, MOTOR2B)
stepper_motor.onestep(direction=stepper.FORWARD)
touch1 = crickit.touch(TOUCH1)
if touch1.value:
print("Touched terminal Touch 1")
Contributing
============
Expand Down
2 changes: 1 addition & 1 deletion examples/crickit_multi_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This is a mock example showing typical usage of the library for each kind of the device.
# This is a mock example showing typical usage of the library for each kind of device.

# crickit is a singleton object
from adafruit_crickit.crickit import crickit
Expand Down

0 comments on commit 1824e9c

Please sign in to comment.