diff --git a/tools/orangepi_rpi_ws2812.py b/tools/orangepi_rpi_ws2812.py new file mode 100644 index 0000000..8cfdee4 --- /dev/null +++ b/tools/orangepi_rpi_ws2812.py @@ -0,0 +1,36 @@ +from rpi_ws281x import PixelStrip, Color +import time + +# LED strip configuration: +LED_COUNT = 8 # Number of LED pixels. +LED_PIN = 16 # 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 + +# 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 color_chase(color, wait): + """颜色追逐效果""" + for i in range(strip.numPixels()): + strip.setPixelColor(i, color) + strip.show() + time.sleep(wait) + +try: + while True: + # 渐变色追逐效果 + for j in range(3): + color_chase(Color(255, 0, 0), 0.1) # 红色 + color_chase(Color(0, 255, 0), 0.1) # 绿色 + color_chase(Color(0, 0, 255), 0.1) # 蓝色 + +except KeyboardInterrupt: + color_chase(Color(0, 0, 0), 0.1) # 关闭时变为黑色 + exit(0) \ No newline at end of file