ledstrip
ledstrip¶
ledstrip module 是 micropython neopixel module的增强版,在neopixel基础功能上封装多种的灯带显示效果。 支持掌控板或micropython的使用。
API接口说明¶
函数¶
-
hsv2rgb
(hsv)¶
HSV转RGB函数,返回rgb 3元组
hsv
(tuple) : HSV 3元组,(h,s,v);范围h(0~360),s/v(0~1.0)
-
rgb2hsv
(rgb)¶
RGB转HSV函数,返回hsv 3元组
rgb
(tuple) : RGB 3元组,(r,g,b);范围0~2555.
-
wheel
(pos)¶
彩环,可将输入0~255值,转换为(r,g,b)值.
pos
: 0~255
LedStrip类¶
继承 NeoPixel
类,在NeoPixel基础上增加显示效果.
构建对象¶
-
class
LedStrip
(pin, n=24, brightness=0.5, timing=1)¶
构建对象
pin
: 控制引脚号,如掌控板P5,则Pin.P5。n
: neopixel 灯数量,默认24brightness
: 亮度,默认0.5,即50%timing
: 数据速率;1时,800kHz,0时,400KHz。
-
clear
()¶
熄灭所有灯
-
write
()¶
数据写入neopixel中。
-
brightness
(brightness)¶
设置亮度
brightness
: 亮度,0~1.0
效果方法¶
-
rainbow
(wait_us=20)¶
彩虹效果
wait_us
: 延时,单位微秒
-
rainbow_cycle
(wait_us=20)¶
与rainbow略有不同,这使得彩虹在整个过程中均匀分布
wait_us
: 延时,单位微秒
-
cycle
(c, wait=20)¶
循环效果,有一个像素在所有灯带位置上运行,而其他像素关闭。
c
: 颜色,类型tuple,(r,g,b)3元组wait
: 延时
-
bounce
(c, wait=20)¶
弹跳效果,等待时间决定了弹跳效果的速度
c
: 颜色,类型tuple,(r,g,b)3元组wait
: 延时
-
colorWipe
(c, wait=10)¶
逐个填充颜色
c
: 颜色,类型tuple,(r,g,b)3元组wait
: 延时
-
theaterChase
(c, wait=50)¶
剧院风格的追逐灯
c
: 颜色,类型tuple,(r,g,b)3元组wait
: 延时
-
theaterChaseRainbow
(wait=50)¶
剧院风格的追逐灯带rainbow效果
wait
: 延时
-
cylonBounce
(c, eye_size, spee_delay, return_delay)¶
我想我们并不是所有人都知道Cylon是什么,但我和那些很酷的机器人一起长大,我肯定想拥有一个。我熟悉骑士骑士(尽管那个时代差不多)?它很亲切 - 类似。这种类型的“扫描仪”通常被称为拉尔森扫描仪, 以Glen Larson的名字命名,Glen Larson是负责制作原始太空堡垒卡拉狄加和骑士骑士电视节目的人。无论如何,这里有一个模拟Cylon移动“眼睛”的效果:一个红色的“眼睛”从左到右,一次又一次地向后移动。 亲切 - 一个充满弹性的球。
c
: 颜色,类型tuple,(r,g,b)3元组eye_size
: 确定运行的LED数量,或:“眼睛”的宽度(外部2,褪色,LED未计数)spee_delay
: 影响眼睛移动的速度,较高的值意味着移动缓慢。return_delay
: 设置应该等待反弹的时间
-
runningLight
(c, wait)¶
这种效应使得多组LED相互追逐。亲切 - 就像你在节日期间用来在商店看到的行车灯一样。
c
: 颜色,类型tuple,(r,g,b)3元组wait
: 延时
-
meteorRain
(c, size, trail_decay, random_decay, delay)¶
流星雨效果
c
: 颜色,类型tuple,(r,g,b)3元组size
: 设置流星大小代表流星的LED数量,不计算流星的尾部trail_decay
: 流星尾部衰减/消失的速度。数字越大,尾部越短和/或消失得越快。理论上,值为64时,每次流星绘制时亮度都会降低25%random_decay
: 随机衰变-通过使衰变有点随机来模仿碎片中的某些差异。如果此值设置为“true”,则会向轨道添加一些随机性。如果将值设置为“false”,则尾部将非常平滑delay
: 延时
示例¶
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | from ledstrip import *
from machine import Pin
strip=LedStrip(pin=Pin.P15,n=24,brightness=0.5)
print("rainbow")
strip.rainbow()
print("rainbow_cycle")
strip.rainbow_cycle()
print("cycle")
strip.cycle((50,50,50))
print("bounce")
strip.bounce((0,0,50))
strip.clear()
print("colorWipe")
strip.colorWipe((0,50,0))
print("theaterChase")
strip.theaterChase((50,0,0))
print("theaterChaseRainbow")
strip.theaterChaseRainbow(wait=5)
print("cylonBounce")
strip.cylonBounce((0,0,50),4,10,50)
print("runningLight")
strip.runningLight((50,50,0),20)
print("meteorRain")
for i in range(5):
strip.meteorRain((100,100,100),8,60,True,20)
|