0

I want to build similar project like this https://youtu.be/EoGVQl3SjGY but with use of RPI 3B+

I only need to code 20LEDs (one strip) to flash randomly in various intensity and colours from (80,0,150) to (200,0,255),, no sound reactivity (only lights).

I have all hardware setup well, using adafruit library ws281x bud don't know how to code an infinite loop of flashing..

my code for now is:

from rpi_ws281x import *
import random

# LED strip configuration:
LED_COUNT      = 20      # Number of LED pixels.
LED_PIN        = 10      # GPIO pin connected to the pixels (18 uses PWM!).
#LED_PIN        = 10      # GPIO pin connected to the pixels (10 uses SPI /dev/spidev0.0).
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 = 255   # 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       # set to '1' for GPIOs 13, 19, 41, 45 or 53

strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ,LED_DMA,LED_INVERT,LED_BRIGHTNESS,LED_CHANNEL)
strip.begin()

for x in range(0,LED_COUNT):
    while True:
        R = random.randint(80,200)
        B = random.randint(150,255)
        strip.setPixelColor(x,Color(R,0,B))

strip.show()

I know I need to somehow set the While true loop to flash/animate LEDs randomly (like with noise effect). For now all the leds are still.

Thanks in advance for help..

Ereen

2
  • this may help ... duckduckgo.com/?q=Raspberry+pi+neopixels&ia=web
    – jsotola
    Nov 9, 2022 at 15:05
  • For starters every time you make a change to a pixel colour strip.show() must be called to actually show it. Your .show() call is sitting outside the while and for loops so never gets called. Also the order of the for and while loops need swapping or you’ll only ever set the first pixel
    – Paul
    Nov 13, 2022 at 10:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.