Micro:bit TinyBit BLE Python Library
Project description
Micro:bit TinyBit BLE Python Library
A Python package to control a custom Robot V2 via Bluetooth Low Energy (BLE) communication. The package provides an API for controlling the robot's movements and LED colors.
Installation
This project uses Poetry for package management. Install Poetry if you haven't already.
To install the package and its dependencies, run:
poetry install
Usage
The example.py
script demonstrates how to use the package to control the robot.
from weallcode_robot import Robot
robot = Robot("WAC")
robot.led(255, 0, 0) # Set the LED color to red
robot.move(100, 100) # Move forward
robot.wait(2) # Wait for 2 seconds
robot.move(0, 0) # Stop the robot
robot.move(-100, 100) # Turn the robot
robot.wait(0.25) # Wait for 0.25 seconds
robot.move(100, 100) # Move forward
robot.wait(1) # Wait for 1 second
robot.move(0, 0) # Stop the robot
robot.move(-100, -100) # Move backward
robot.wait(1) # Wait for 1 second
robot.move(0, 0) # Stop the robot
robot.led(0, 0, 0) # Turn off the LED
a = robot.setKeyBinding('a').led(0, 0, 255, 1) # set LED color one button A
w = robot.setKeyBinding('w').move(100, 100) # bind move forward to key W
API
Robot
The Robot
class is the main class to control the robot. Instantiate the class with the name of the robot.
robot = Robot("WAC")
Methods
led(red: int, green: int, blue: int, duration: int)
: Sets the LED color. Values should be integers between 0 and 255.move(left: int, right: int, duration: int)
: Sets the motor speeds. Values should be integers between -100 and 100.wait(duration: float)
: Adds a wait command with a given duration in seconds.run()
: Executes the commands in the order they were added.
Development
The package includes development dependencies:
black
: Code formatterpre-commit
: Pre-commit hooks for code formatting and lintingisort
: Import sorterruff
: Linter
To install the development dependencies, run:
poetry install --extras dev
To run the pre-commit hooks, first install them:
pre-commit install
Then run:
pre-commit run --all-files
Authors
- Blaine Rothrock
- Ali Karbassi
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file weallcode_robot-3.1.2.tar.gz
.
File metadata
- Download URL: weallcode_robot-3.1.2.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db90940ddc87b6d361da9372ec3f65710b7fb5bf3b82b5baf90f2baffdaa6081 |
|
MD5 | 55bd5df039fc0be66e22c6b79c30c87d |
|
BLAKE2b-256 | b8353f0817a6c7e7e79f7b9bf3d3d17ab243756927863942cc3026bc3e5b1508 |
File details
Details for the file weallcode_robot-3.1.2-py3-none-any.whl
.
File metadata
- Download URL: weallcode_robot-3.1.2-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd0c8beaee79a43c06a760d4da37e14d8b468fb321afb2539f03e896d9ae35ea |
|
MD5 | a4d79c1caedeb3a590f518f66a019686 |
|
BLAKE2b-256 | fd2a719447c668fd11b54fe05c37c4595a4464153fa5d3b5b1426bdbb6e0d43b |