PFx Brick Python API
This repository contains a python package API for developing python scripts and applications which communicate with the PFx Brick. This package supports both USB and Bluetooth LE connections to the PFx Brick and is supported for Windows, macOS and linux.
The pfxbrick package can be installed with pip:
$ pip install pfxbrick
or directly from the source code:
$ git clone https://github.com/fx-bricks/pfx-brick-py.git $ cd pfx-brick-py $ python setup.py install
After installation, the package can imported:
$ python >>> import pfxbrick >>> pfxbrick.__version__
An example of the package can be seen below
import time from pfxbrick import * # Open a PFx Brick session instance brick = PFxBrick() brick.open() # Get the PFx Brick configuration settings brick.get_config() brick.print_config() # Get the user defined name of the PFx Brick brick.get_name() print(brick.name) # Change the user defined name brick.set_name('My Cool Brick') # Turn on some lights for 5 sec brick.light_on([1, 2, 7, 8]) time.sleep(5) brick.light_off([1, 2, 7, 8]) # Set motor channel A to 50% speed gradually for speed in range(50): brick.set_motor_speed(, speed) time.sleep(0.1) brick.stop_motor() # Play an audio file with indefinite repeat brick.repeat_audio_file("LongBeep1") time.sleep(5) brick.stop_audio_file("LongBeep1") # End the session brick.close()
- PFx Brick Interface Control Document (ICD) v.3.37 describes details of PFx Brick operation and communication protocol
- Python API Reference Documentation
If you want to learn more about PFx Brick, check out our website.