led_strip.py 1.4 KB
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
config and init 24-LEDs-stripe
"""
from neopixel import *

# import logger
from rpi_ws281x import Adafruit_NeoPixel, Color,PixelStrip

LED_COUNT      = 750      # 要控制LED的数量.
# LED_PIN        = 18   # GPIO接口 (PWM编码).
LED_BRIGHTNESS = 100    # 设置LED亮度 (0-255)
#以下LED配置无需修改
LED_FREQ_HZ    = 800000  # LED信号频率(以赫兹为单位)(通常为800khz)
LED_DMA        = 10       # 用于生成信号的DMA通道(尝试5)
LED_INVERT     = False   # 反转信号(使用NPN晶体管电平移位时)
LED_CHANNEL = 0
stop_flag = None


def get_strip(pin=12):
    LED_PIN = pin
    strip = PixelStrip(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS,LED_CHANNEL)
    # Initialize the library (must be called once before other functions).
    # log.debug("Initialize: " + str(strip))
    strip.begin()
    return strip

def color_wipe_full(strip, color, wait_ms=50):
    """Wipe color across display a pixel at a time."""
    for i in range(strip.numPixels()):
        strip.setPixelColor(i, color)
    strip.show()
        # time.sleep(wait_ms/1000.0)


def reset_strip(strip):
    strip.setBrightness(LED_BRIGHTNESS)
    color_wipe_full(strip, Color(0,0,0), 20)
    # log.debug('LED stripe cleared.')
    return


# noinspection PyProtectedMember
def _cleanup_strip(strip: Adafruit_NeoPixel):
    strip._cleanup()