jgarff / rpi_ws281x

Userspace Raspberry Pi PWM library for WS281X LEDs
BSD 2-Clause "Simplified" License
1.78k stars 622 forks source link

LEDs flash white randomly #464

Open ksrm0024 opened 3 years ago

ksrm0024 commented 3 years ago

Hey all,

I'm controlling two inline 1x8 LED strips and run into an issue where when I try to control them as part of a larger script, they constantly flash white at full brightness to the point where they are white more often than they are the color I want them to be. Is there some way to sort of stabilize them? I'll post part of my code below. Apologies if the fix is obvious - I'm new to raspberry pi in general and this is the first project I have used it for.

Thanks!

` import neopixel pixels = neopixel.NeoPixel(board.D10, 16) while running: rot3pos1 = GPIO.input(20) rot3pos2 = GPIO.input(21) rot3pos3 = GPIO.input(26)

    if rot3pos1 == False:
        rpm_mult = 4.615

    elif rot3pos2 == False:
        rpm_mult = 1.58

    elif rot3pos3 == False:
        rpm_mult = 1

    else:
        rpm_mult = 3.833

    rpmfrac = (rpm-700) / 6000
    rpmfrac2 = rpmfrac * rpm_mult

    if rpmfrac2 > 0.125:  
        pixels[0] = (0, 30, 0)
        pixels[15] = (0, 30, 0)

    if rpmfrac2 > 0.25:  
        pixels[1] = (0, 30, 0)
        pixels[14] = (0, 30, 0)

    if rpmfrac2 > 0.375:  
        pixels[2] = (0, 30, 0)
        pixels[13] = (0, 30, 0)

    if rpmfrac2 > 0.5:  
        pixels[3] = (0, 30, 0)
        pixels[12] = (0, 30, 0)

    if rpmfrac2 > 0.625:  
        pixels[4] = (0, 30, 0)
        pixels[11] = (0, 30, 0)

    if rpmfrac2 > 0.75:  
        pixels[5] = (0, 30, 0)
        pixels[10] = (0, 30, 0)

    if rpmfrac2 > 0.875:  
        pixels[6] = (0, 30, 0)
        pixels[9] = (0, 30, 0)

    if rpmfrac2 > 1:  
        pixels.fill((0,0,50))`
ranjithp97 commented 3 years ago

Hi @ksrm0024 Do you want to change the brightness of the LED?