Skip to main content

Non-blocking LED controlling library

Project description

Introduction

Build Status Code Style: Black API Documentation

An embedded library for Python to control LEDs. It uses a non-blocking approach and can control LEDs in simple (on/off) and complex (blinking, breathing and more) ways in a time-driven manner.

This is a pure Python port of my JLed C++ library.

JLed in action

Features

  • non-blocking

  • effects: simple on/off, breathe, blink, candle, fade, user-defined

  • supports inverted polarity of LED

  • easy configuration using fluent interface

  • can control groups of LEDs sequentially or in parallel

  • supports CircuitPython and MicroPython

Usage Example

Test JLed interactively in a CircuitPython REPL:

Adafruit CircuitPython 7.3.3 on 2022-08-29; Raspberry Pi Pico with rp2040
>>> import board
>>> from jled import JLed
>>> led=JLed(board.LED).breathe(500).delay_after(250).repeat(5)
>>> while led.update(): pass

This creates a JLed object connected to the builtin LED (board.LED), with a breathe effect that is repeated 5 times. Each iteration is followed by a delay of 250 ms, before starting again. By calling led.update() periodically, the LED gets physically updated. Alternatively play(led) can be call in the REPL as a shortcut. Once finished, call led.reset() before playing the effect again.

Cheat Sheet

https://cdn.jsdelivr.net/gh/jandelgado/jled-circuitpython@v1.0.2/.images/jled_cheat_sheet.jpg

Installation

On supported GNU/Linux systems like the Raspberry Pi (with Adafruit-Blinka), you can install the lib locally from PyPI. To install for current user:

pip3 install circuitpython-jled

To install system-wide (this may be required in some cases):

sudo pip3 install circuitpython-jled

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .env/bin/activate
pip3 install circuitpython-jled

Installing to a Connected CircuitPython Device

Create a directory called jled on the device and copy the following files into this directory: jled.py, jled_sequence.py hal_pwm_circtuitpython.py, hal_time_circuitpython.py, play.py, __init__.py`. Optionally also copy the jled_micropython.py example as main.py to the root of the filesystem. The overall structure is:

/
├─ main.py
└─ jled
    ├─ __init__.py
    ├─ hal_pwm_circuitpython.py
    ├─ hal_time_circuitpython.py
    ├─ jled.py
    ├─ jled_sequence.py
    └─ play.py

Installing to a Connected CircuitPython Device with Circup

TODO

Installing on a MicroPython device

Create a directory called jled on the device and copy the following files into this directory: into this directory: jled.py, jled_sequence.py hal_pwm_micropython.py, hal_time_micropython.py, play.py, __init__.py`. Optionally also copy one of the example as main.py to the root of the filesystem. The overall structure is:

/
├─ main.py
└─ jled
    ├─ __init__.py
    ├─ hal_pwm_micropython.py
    ├─ hal_time_micropython.py
    ├─ jled.py
    ├─ jled_sequence.py
    └─ play.py

To reduce memory consumption, Python source files can be compiled to binary mpy format using the mpy-cross tool. For convenience, a script to compile and copy jled to a connected device is provided here (see scripts/install_mp.sh.

Documentation

API documentation for this library can be found on here.

Rebuild the documentation with sphinx-build -E -W -b html . _build/html in the docs directory. Run pip install ".[optional]" before to install build-time dependency Sphinx

Tests

Unit tests (using https://docs.pytest.org) are provided, run the tests with:

$ pip install ".[optional]"
$ pytest

To run the pre-commit-hook locally, run pre-commit run --all-files

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

circuitpython-jled-1.0.2.tar.gz (1.0 MB view details)

Uploaded Source

Built Distribution

circuitpython_jled-1.0.2-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file circuitpython-jled-1.0.2.tar.gz.

File metadata

  • Download URL: circuitpython-jled-1.0.2.tar.gz
  • Upload date:
  • Size: 1.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for circuitpython-jled-1.0.2.tar.gz
Algorithm Hash digest
SHA256 806f810394f12af77dd9278c47f7adf58116b37a1e18fd019d266086b1e74d77
MD5 21d098fcdc30b352dbc2721147210c87
BLAKE2b-256 1b89c237b2932894794413c7b88c718d34d71c875309674cc8e18f3259a35927

See more details on using hashes here.

File details

Details for the file circuitpython_jled-1.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for circuitpython_jled-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 160f10ca2f317f9eb733ce5e020831aa0485bb7bf2ac65fd9d43c64e34c8bcf5
MD5 79ac7edc50d0fd39f214ab04126dd48d
BLAKE2b-256 420da108dbaa302e4e07bb1f2b0cc2e39b409bb0b6898ef1626b0e591aa7e2d9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page