用户工具

站点工具


circuitpython:其它:2线方式驱动ws2812

只用DIN和GND两线驱动 WS2812。需要对电路做一点改动,在DIN和VCC之间连接一个肖特基二极管,再并联10uF电容。

# neopixel_2wire_code.py -- demonstrate doing 2-wire Neopixel strip
#  Tested on ItsyBitsy 2040 with CircuitPython 7.0
# To modify your strip to be a 2-wire strip: 
# - Put a Shottkey diode across Din -> Vin
# - Put a 10uF capacitor across Vin & Gnd
# - Run two wires from microcontroller : Din + Ground
# - Data line can be a 3V3 pin but a 5V pin works better
# - Only drive about 4 LEDs on a single pin
# - Brightness can be only about 20% max
#
# 2021 - @todbot / Tod Kurt
# More info: https://twitter.com/todbot/status/1461838809662779392
#
import random, time
import board 
import neopixel, rainbowio

led = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.4) # onboard LED 
leds = neopixel.NeoPixel(board.D5, 4, brightness=0.1, auto_write=False) # our 2-wire strip

def leds_show():
    leds.pin.value = False # drop pin low so WS2812 protocol starts correctly
    leds.show()
    leds.pin.value = True  # raise pin high so strip stays powered

n = 0
while True:
    # simple moving rainbow on strip
    for i in range(len(leds)):
        color =  rainbowio.colorwheel( (i*256)/len(leds) + n  ) 
        leds[i] = color 
    leds_show()
    n = (n+1) % 1000
    
    led.fill( color )  # show last color on on-board neopixel
    
    time.sleep(0.01)
#    print("%d:%6x" % (n, color) )

https://gist.github.com/todbot/308fd1de936c1670194528362a815efb



purge    随机主题   
circuitpython/其它/2线方式驱动ws2812.txt · 最后更改: 2021/12/02 08:43 由 shaoziyang · 查看次数: 8889