codex
– CodeX hardware interface¶
Core low-level module for CodeX
- The codex module gives you direct access to all the hardware on the CodeX.
power =
Power
buttons =
Buttons
leds =
LEDs
pixels =
NEOPixels
display =
canvas.Canvas
audio =
codec.Codec
light =
AmbientLight
exp =
Expansion
tft =
tft.TFT
-
class
codex.
AmbientLight
(i2c, power)[source]¶ Access to the CodeX ambient light sensor.
This device has two light sensors. One reads only infrared light. The other reads infrared light and visibile light at the same time.
-
read
()[source]¶ Read the infrared plus visible light level ADC value. Value depends on current gain setting.
- Returns
visible + infrared
- Return type
-
read_ir
()[source]¶ Read the IR light level ADC value. Value depends on current gain setting.
- Returns
ir light
- Return type
-
-
codex.
BTN_A
= 4¶ A
-
codex.
BTN_B
= 5¶ B
-
codex.
BTN_D
= 2¶ DOWN
-
codex.
BTN_L
= 3¶ LEFT
-
codex.
BTN_R
= 1¶ RIGHT
-
codex.
BTN_U
= 0¶ UP
-
class
codex.
Buttons
(io_expander)[source]¶ Access to pushbutton switches BTN-0 through BTN-5. Buttons can be referenced by
int
value 0-5, or by symbolic names:BTN_U
,BTN_R
,BTN_D
,BTN_L
,BTN_A
,BTN_B
-
is_pressed
(num=None)[source]¶ Return True if specified button is pressed, or tuple of status for all buttons if num=None.
- Parameters
num (int/None) – 0-5 or None
- Returns
bool if num was an int else a tuple of all values
- Return type
value (bool/tuple)
-
was_pressed
(num=None)[source]¶ Return True if specified button was pressed since last call of this function. Default with num=None, returns tuple of status for all buttons since last call.
- Parameters
num (int/None) – 0-5 or None
- Returns
bool if num was an int else a tuple of all values
- Return type
value (bool/tuple)
-
-
class
codex.
Expansion
[source]¶ Access to Expansion connectors and Peripheral ports. This class provides some functions to simplify use of the available expansion pins, but feel free to use CircuitPython hardware interface functions such as
digitalio
,analogio
, andbusio
directly with these GPIO pins as well.-
GPIO0
¶
-
GPIO1
¶
-
GPIO2
¶
-
GPIO3
¶
-
GPIO4
¶ Expansion Connectors
-
PORT0
¶
-
PORT1
¶
-
PORT2
¶
-
PORT3
¶ Peripheral Connectors
-
make_pwm
(pin, duty_cycle=0, frequency=50)[source]¶ Connect a PWM (pulse width modulation) peripheral to the specified pin. This can be used to control servos, or as a general-purpose oscillating output.
- Parameters
pin – The IO pin to use, for example exp.PORT1
duty_cycle – duration pin is high during each period, with 65535 being 100%.
frequency – periodic oscillation frequency in Hz (cycles per second)
- Returns
The PWMOut object bound to specified pin.
- Return type
-
release_pwm
(pwm)[source]¶ Disconnect the internal PWM peripheral previously bound to a pin.
- Parameters
pwm – A PWM peripheral created with make_pwm()
-
set_servo
(pwm, position_pct)[source]¶ Set the position of a servo controlled with a PWM output. The PWM frequency must be 50Hz (default value of make_pwm()). Note: Many servos require position_pct value to exceed the ±100 range to reach their mechanical limits. Also an offset may be needed to center the servo.
- Parameters
pwm – A PWM output created with make_pwm().
position_pct – Desired servo position with “nominal” range -100 to +100. A value of 0 will “center” the servo.
-
-
codex.
LED_A
= 5¶ LED A
-
codex.
LED_B
= 4¶ LED B
-
class
codex.
LEDs
(io_expander)[source]¶ Access to the six LEDs on the CodeX.
-
class
codex.
NEOPixels
[source]¶ Access to the four CodeX neopixels.
-
fill
(value, brightness=10)[source]¶ Set all NeoPixels to a single color.
- Parameters
value (tuple) – A tuple of three values for RGB like (10,88,102)
-
get
(num=None)[source]¶ Get current RGB value of Codex NeoPixels. This will be the value after brightness was applied.
- Parameters
num (int/None) – A number from 0 - 3 will return a single value, None will return tuple of all 4 values.
- Returns
value (tuple/tuple of 4 tuples)
-
-
class
codex.
Power
(io_expander)[source]¶ Access to the CodeX power control and power monitoring.
-
enable_batt_meas
(do_enable)[source]¶ Enable the battery measurement ability.
- Parameters
do_enable – True to enable measurement or False to disable
-
enable_periph_vcc
(do_enable, guarded=True)[source]¶ Enable power (+5V) for peripheral devices.
- Parameters
do_enable – True to enable power for peripheral devices
guarded – Protect CPU power from dipping due to peripheral surges.
-
get_battery_current
()[source]¶ Measure the power supply current consumption (battery or USB).
- Returns
Current consumption in milliamps
- Return type
-
get_battery_voltage
()[source]¶ Measure the power supply voltage (battery or USB).
- Returns
Power supply voltage
- Return type
-
is_batt_meas_enable
()[source]¶ Is the battery measurement ability enabled?
- Returns
True if the measurement ability is enabled
- Return type
-