Skip to main content

A library to control the onboard LEDs on a Raspberry Pi

Project description

RPiLEDController

This Python can be used to easily control the onboard-leds of a Raspberry Pi Currently the following RPis are supported:

  • any Raspberry Pi 4
  • any Raspberry Pi 5

Installation

To install the package, simply run the following command:

pip install RPiLEDController

Usage

To use the package, simply import it and create an instance of the RPiLEDController class:

from RPiLEDController.RPiLEDController import RPiLEDController

led_controller = RPiLEDController()

At the end of your code, add the following line to release the leds:

led_controller.release()

ALWAYS USE SUDO TO RUN THE CODE

You will get this error if you don't use sudo: PermissionError: [Errno 13] Permission denied: '/sys/class/leds/led1/trigger'

Methods

The following methods are available:

act_off

Turns the green activity led off

act_on

Turns the green activity led on

act_release

Resets the trigger of the green activity led to "mmc0"

act_reserve

Sets the trigger of the green activity led to "none"

pwr_off

Turns the red power led off

pwr_on

Turns the red power led on

pwr_release

Resets the trigger of the red power led to "default-on"

pwr_reserve

Sets the trigger of the red power led to "none"

reserve

Sets the trigger of the red power led to "none" and the trigger of the green activity led to "none"

release

Resets the trigger of the red power led to "default-on" and the trigger of the green activity led to "mmc0"

Example

from RPiLEDController.RPiLEDController import RPiLEDController
import time

led_controller = RPiLEDController()

for i in range(10):
	led_controller.act_off()
	time.sleep(1)
	led_controller.pwr_on()
	time.sleep(1)
	led_controller.act_on()
	time.sleep(1)
	led_controller.pwr_off()
	time.sleep(1)

led_controller.release()

This code will turn the green activity led off and the red power led on. At the end of the code, the triggers of both leds will be reset to their default values.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

RPiLEDController-0.1.7-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

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