🌈 MohuanLED Bluetooth Control
BJ_LED_M is a Python library designed to control MohuanLED brand lights via Bluetooth, directly from your laptop or PC (you’ll need a Bluetooth adapter if it’s not built-in). This library allows you to perform simple actions like turning the lights on/off, changing colors, and applying animations or reactions to external events. It also includes a PyQt6-based GUI for more intuitive control over the lights. 🌟
🚀 Usage
The library is fully asynchronous, so you'll need to use asyncio and await. Here's an example of how to establish a direct connection, knowing the UUID and MAC address of the LEDs:
from bluelights import BJLEDInstance
import asyncio
ADDRESS = '64:11:a8:00:8b:a6' # Example address
UUID = '0000ee02-0000-1000-2000-00805f9b34fb' # Example UUID
async def main():
led = BJLEDInstance(address=ADDRESS, uuid=UUID)
try:
await led.turn_on()
await led.set_color_to_rgb(255, 0, 0) # Change color to red (RGB)
await asyncio.sleep(5) # Wait 5 seconds
await led.turn_off() # Turn off LEDs and disconnect
except Exception as e:
print(e)
finally:
await led._disconnect() # Clear the buffer
asyncio.run(main())
A dynamic example with the same orders:
from bluelights import BJLEDInstance
import asyncio
async def main():
led = BJLEDInstance() # The Scanner will look for 'BJ_LED_M' (name of the devices) and connect
try:
await led.turn_on()
await led.set_color_to_rgb(255, 0, 0) # Change color to red (RGB)
await asyncio.sleep(5) # Wait 5 seconds
await led.turn_off() # Turn off LEDs and disconnect
except Exception as e:
print(e)
finally:
await led._disconnect() # Clear the buffer
asyncio.run(main())
⚙️ Features
- Control MohuanLED lights via Bluetooth (BLE)
- Turn the LEDs on and off 💡
- Change colors across the full RGB spectrum 🎨
- Apply effects like:
- 🔄 Color fade
- 💡 Color strobe
- 🌬️ Breathing effect between colors
- 🌈 Rainbow cycle
- 🌊 Wave effect
- Graphical user interface (GUI) using PyQt6 (In development 🛠️)
- Command Line Interface (CLI) for basic commands (In development 🛠️)
- Dynamic MohuanLED device scanner for easy connections (In development 🛠️)
- Automatic detection of UUIDs and MAC addresses
🛠️ Installation
Requirements
- Python 3.8 or higher
- PyQt6 and qasync
- Built-in or external Bluetooth adapter
- MohuanLED lights
You can install the library via pip:
pip install BlueLights
Or install it directly from the repository:
git clone https://github.com/Walkercito/MohuanLED-Bluetooth_LED
cd BlueLights
pip install .
🌈 Applying Effects
You can add various effects to the lights, such as rainbow_cycle, wave_effect, or strobe_light. Here are a few examples:
# Apply the 'rainbow_cycle' effect
await led.rainbow_cycle(duration_per_color=5.0)
# Apply the 'strobe_light' effect with 10 flashes
await led.strobe_light(color=(255, 255, 255), duration=5.0, flashes=10)
🖥️ GUI Control
The library also provides a graphical user interface (GUI) built with PyQt6 to visually control the lights.
To launch the GUI:
python -m bluelights.gui.app
The GUI includes sliders to adjust RGB values and buttons to control the lights and apply effects like fading and color cycling.
⚙️ Configuration
You can configure your setup using an .env file to store your MohuanLED light’s MAC address and UUID.
Create a .env file in the project directory with the following structure:
LED_MAC_ADDRESS=xx:xx:xx:xx:xx:xx
LED_UUID=0000xxxx-0000-1000-8000-00805f9b34fb
The library will automatically load these values when you instantiate the LEDs.
🛠️ Development
If you want to contribute or modify the project, you can set up the development environment as follows:
Clone the repository:
git clone https://github.com/Walkercito/MohuanLED-Bluetooth_LED
Install the dependencies:
pip install -r requirements.txt
📜 License
This project is licensed under the MIT License. See the LICENSE file for more details.
Acknowledgments
- Bleak: For Bluetooth Low Energy (BLE) device control 🔗
- PyQt6: For creating the graphical interface 🖼️
- asyncio: For asyncronus tasks
- qasync: For handling asynchronous processes in PyQt6 ⚡
- python-dotenv: For auto-loading of LED_MAC_ADDRESS and LED_UUID in case of a
.envfile - nest_asyncio: For asyncio control
Metadata
Release files for BlueLights 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bluelights-0.3.1.tar.gz | 8.1 kB | Without provenance | Details for bluelights-0.3.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| BlueLights-0.3.1-py3-none-any.whl | Python 3 | none | any | Details for BlueLights-0.3.1-py3-none-any.whl |
Total release size: 16.6 kB
Release files / bluelights-0.3.1.tar.gz
| Download URL | bluelights-0.3.1.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9841c3e8fdf4440eaa0a2e3127feb2a69f4a707fdce09f9b4572212690db5419
|
|
BLAKE2b-256 checksum How to use checksums |
f32251b9ea9fb9ab53b70838ece28cab22d052139d7e8625b180fa79be377e11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / BlueLights-0.3.1-py3-none-any.whl
| Download URL | BlueLights-0.3.1-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be7ff22a57e7b688dd1f9ecdeb27e3bce0481785dc5a35735bb62af93bebb819
|
|
BLAKE2b-256 checksum How to use checksums |
97e17ceeac7a5fd291f4d2c3207a4d719e0d205d46373ad15819aefa1952e1f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Security for BlueLights 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.