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: GPIOPinInterface, *, initial_mode: Union[Type[DerivedComponent], GPIOPinMode], hardware_modes: Set[GPIOPinMode] = {GPIOPinMode.DIGITAL_OUTPUT}, firmware_modes: Set[Type[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[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[DerivedComponent], 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: PiezoInterface, *, default_blocking: bool = False)[source]
A standard piezo.
- buzz(duration: Union[int, float, timedelta], pitch: Union[int, float, 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
PowerOutput
- class j5.components.PowerOutput(identifier: int, backend: 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: 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, 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, 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: 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: GPIOPin, gpio_echo: GPIOPin, backend: 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:
RuntimeError – distance mode is disabled.