Components
A component is the smallest logical part of some hardware.
A component will have the same basic functionality no matter what hardware it is on.
Battery Sensor
GPIOPin
- class j5.components.GPIOPin(identifier: int, backend: j5.components.gpio_pin.GPIOPinInterface, *, initial_mode: Union[Type[j5.components.component.DerivedComponent], j5.components.gpio_pin.GPIOPinMode], hardware_modes: Set[j5.components.gpio_pin.GPIOPinMode] = {GPIOPinMode.DIGITAL_OUTPUT}, firmware_modes: Set[Type[j5.components.component.DerivedComponent]] = {})[source]
A GPIO Pin.
- analogue_read() float [source]
Get the scaled analogue reading of the pin.
- Returns
scaled analogue reading
- analogue_write(new_value: float) None [source]
Set the analogue value of the pin.
- Parameters
new_value – analogue value
- Raises
ValueError – pin value must be between 0 and 1
- digital_read() bool [source]
Get the digital state of the pin.
- Returns
digital read state of the pin.
- digital_write(state: bool) None [source]
Set the digital state of the pin.
- Parameters
state – digital state.
- property firmware_modes: Set[Type[j5.components.component.DerivedComponent]]
Get the supported firmware modes.
- Returns
supported firmware modes.
- property last_digital_write: bool
Get the last set digital state of the pin.
This does not perform a read operation, it only gets the last set value, which is usually cached in memory.
- Returns
last set digital state of the pin
- property mode: Union[Type[j5.components.component.DerivedComponent], j5.components.gpio_pin.GPIOPinMode]
Get the mode of this pin.
- Returns
current mode of the pin.
- pwm_write(new_value: float) None [source]
Set the PWM value of the pin.
- Parameters
new_value – new duty cycle
- Raises
ValueError – pin value must be between 0 and 1
LED
Motor
Piezo
- class j5.components.Piezo(identifier: int, backend: j5.components.piezo.PiezoInterface, *, default_blocking: bool = False)[source]
A standard piezo.
- buzz(duration: Union[int, float, datetime.timedelta], pitch: Union[int, float, j5.components.piezo.Note], *, blocking: Optional[bool] = None) None [source]
Queue a note to be played.
Float and integer durations are measured in seconds.
A buzz can either be blocking, or non-blocking and will fall back to a default if it is not specified.
- Parameters
duration – length to play for
pitch – pitch of buzz.
blocking – whether the code waits for the buzz
- static verify_duration(duration: datetime.timedelta) None [source]
Verify that a duration is valid.
- Parameters
duration – duration to validate.
- Raises
TypeError – duration must be a timedelta.
ValueError – duration cannot be negative.
PowerOutput
- class j5.components.PowerOutput(identifier: int, backend: j5.components.power_output.PowerOutputInterface)[source]
A power output channel.
It can be enabled/disabled, and the current being drawn on this channel can be measured.
PWMLED
RGBLED
- class j5.components.RGBLED(identifier: int, backend: j5.components.rgb_led.RGBLEDInterface)[source]
A Light Emitting Diode, driven by a PWM output.
This usually means that the LED is of variable brightness.
- property blue: float
Get the current value of the blue channel.
- Returns
current duty cycle of the blue channel.
- get_channel(channel: Union[str, j5.components.rgb_led.RGBColour]) float [source]
Get the current value of a channel.
- Parameters
channel – The channel to get the value for.
- Returns
The duty cycle for the channel.
- Raises
ValueError – channel is not a valid RGB channel.
- property green: float
Get the current value of the green channel.
- Returns
current duty cycle of the green channel.
- property red: float
Get the current value of the red channel.
- Returns
current duty cycle of the red channel.
- property rgb: Tuple[float, float, float]
Get a tuple of the channel duty cycles.
- Returns
tuple of duty cycles (R, G, B).
- set_channel(channel: Union[str, j5.components.rgb_led.RGBColour], duty_cycle: float) None [source]
Set the current value of a channel.
- Parameters
channel – The channel to get the value for.
duty_cycle – The duty cycle to set the channel to.
- Raises
ValueError – channel is not a valid RGB channel.
ValueError – duty cycle is not in expected range.
Servo
StringCommand
- class j5.components.StringCommandComponent(identifier: int, backend: j5.components.string_command.StringCommandComponentInterface)[source]
A string command component.
This component allows the sending and receiving of commands to a board, so that custom ASCII protocols can be implemented. This is primarily aimed at Boards which can have custom firmware installed by the students that are using them.
- execute(command: str) str [source]
Execute the string command and return the result.
This function can be synchronous and blocking.
- Parameters
command – command to execute.
- Returns
result of command.
- Raises
ValueError – command is not valid.
UltrasoundSensor
- class j5.components.derived.UltrasoundSensor(gpio_trigger: j5.components.gpio_pin.GPIOPin, gpio_echo: j5.components.gpio_pin.GPIOPin, backend: j5.components.derived.ultrasound.UltrasoundInterface, *, distance_mode: bool = True)[source]
Ultrasonic distance sensor.
A sensor that utilises the reflection of ultrasound to calculate the distance to a nearby object.
- distance() Optional[float] [source]
Send a pulse and return the distance to the object.
- Returns
Distance measured in metres, or None if it timed out.
- Raises
Exception – distance mode is disabled.
- pulse() Optional[datetime.timedelta] [source]
Send a pulse and return the time taken.
- Returns
Time taken for the pulse, or None if it timed out.