rpi-ws281x / rpi-ws281x-python

Python library wrapping for the rpi-ws281x library
BSD 2-Clause "Simplified" License
323 stars 103 forks source link

color 0 to 255 is not consistant increase in red brightness - same for other colours. #105

Closed anwarbashir closed 11 months ago

anwarbashir commented 11 months ago

Hi, I have four ws281 pixels installed on my board connected to GPIO pin 10. I have based my program around strandtest.py, but I wanted to address each pixel individually. But when I run the program it starts with red but at various point turns blue, I need to exclude these numbers. Can you advise a fix: import time from rpi_ws281x import PixelStrip, Color

LED strip configuration

LED_COUNT = 4 # Number of LED pixels. LED_PIN = 10 # GPIO pin connected to the pixels (18 uses PWM!). LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) LED_DMA = 10 # DMA channel to use for generating signal (try 10) LED_BRIGHTNESS = 127 # Set to 0 for darkest and 255 for brightest LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) LED_CHANNEL = 0

Create NeoPixel object with appropriate configuration.

strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)

Intialize the library (must be called once before other functions).

strip.begin()

def set_led_color(index, color): """ Set the color of an individual LED on the strip.

Args:
    index (int): Index of the LED (0-based).
    color (tuple): RGB color tuple (e.g., (255, 0, 0) for red).
"""
strip.setPixelColor(index, Color(*color))
strip.show()

Example usage:

try: i = 0 while i <= 127:

Set LED 0 to red color.

    print(i)
    set_led_color(0, (i, 0, 0))  # Red
    time.sleep(1)
    i += 1

except KeyboardInterrupt:

Turn off all pixels and clean up resources when Ctrl+C is pressed.

for j in range(strip.numPixels()):
    strip.setPixelColor(j, Color(0, 0, 0))  # Turn off
strip.show()
anwarbashir commented 11 months ago

The solution was to increase the LED_COUNT to over 6, see other post. Now seems to be working fine.