仅用 2 根线驱动 WS2812

Adafruit CircuitPython相关
MicroPython重要分支
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

仅用 2 根线驱动 WS2812

#1

帖子 shaoziyang »

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

图片

Code: Select all

# 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
 
 
 [/i]
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章