This repo contains the CircuitPython library that allows you to program your gizmo controller using the CircuitPython environment.
You must have installed and configured CircuitPython.
Some examples use libraries from the Adafruit Bundle.
Some examples use the adafruit_simplemath module. This can be installed following a similar process as is outlined below.
To manually install the Gizmo library onto your CircuitPython device:
To install the Gizmo library using the CircUp tool:
Add the bundle to your local list.
circup bundle-add gizmo-platform/CircuitPython_Gizmo
Install the module to your connected device.
circup install circuitpython_gizmo
Access to Gizmo features is provided through the Gizmo
class.
from circuitpython_gizmo import Gizmo
gizmo = Gizmo()
You can access the gamepad state with gizmo.buttons
and
gizmo.axes
.
# True if the A button is pressed. False if not.
gizmo.buttons.a
# Position of the left vertical stick from 0 to 255
gizmo.axes.left_y
You must call gizmo.refresh()
at a regular interval to get
the latest information from the Gizmo. Most Gizmo programs will
have this structure:
from circuitpython_gizmo import Gizmo
# other imports...
gizmo = Gizmo()
# setup motors / sensors...
while True:
gizmo.refresh()
# do robot tasks...
Finally, the Gizmo class has variables you can use to refer to
specific ports on the Gizmo board when working with other
CircuitPython features. For example, gizmo.MOTOR_1
refers to
motor port 1 on the Gizmo board and can be used with the
pwmio
module to control Gizmo motors.
# Control motor port 1 as a PWM output
motor_pwm = pwmio.PWMOut(gizmo.MOTOR_1, frequency=50)
See the examples folder for complete code files demonstrating how to use this library.