用arduino作为继电器控制neopixel led条带的高级接口

neopyxel的Python项目详细描述


新生儿

Python库,通过一个串行连接的Arduino继电器,可以轻松控制Adafruit的neopxel LED条纹。在

实现的功能

这个库提供了一个易于使用的高级接口来控制Adafruit的Neopixel LED条纹或任何由WS281x控制并由Adafruit's Neopixel Arduino library支持的单独寻址LED条带。这使得开发人员能够利用Python的所有资源和灵活性来开发LED条纹的效果和集成,方法是通过在运行Python的设备和条纹本身之间充当中继的arduino将命令中继到条纹上。在

为此,库使用串行通信向Arduino中继发送命令,并实现一系列类来抽象物理细节和通信过程,总结如下:

NeopyxelRelay对象

建立并处理与Arduino中继和条纹对象的连接。在

add_stripe()# Enables dynamic configuration of stripes on the Arduino Relayflush_stripes()# Flushes stripes setted up on the Arduino Relayset_pixel_color()# Enables concurrent pixel color setting of all stripes connected to the relayshow()# Enables concurrent update of pixels' display of all stripes connected to the relayseg_segment_color()# Enable concurrent control of stripes segments by abstracting stripes length through # relative segment position and length referencingexecute_effect()# Executes an effect defined by Effect classstop_effect()# Stops execution of an effect defined by Effect class

条纹对象

表示连接到中继的特定条带。在

^{pr2}$

效果对象

通过实例化继承Effect类的类来定义Effect对象。Effect类为led条纹效果的快速开发和包装提供了一个接口。通过使用set_segment_color函数,可以编写效果,而不管要在其上执行的LED条纹的物理特性如何。效果由一个定义要执行的效果的主函数和两个定义如何启动和终止效果的转换对象组成。在

安装

Arduino继电器设置步骤

  1. 加载neopyxel_relay.ino文件,该文件位于Arduino板上的neopyxel_relay目录下。在
  2. 将Arduino板连接到将通过USB运行Python代码的设备。在
  3. 将LED条纹数据管脚连接到Arduino上的数字管脚(注意所选的数字管脚,稍后会用到)。在
Python安装程序

使用包管理器pip安装neopyxel。在

pip install neopyxel

使用

简单的像素颜色设置:

importneopyxel# Instantiate NeopyxelRelay (no arguments are needed, but the COMPORT can be specified in case the detection fails)relay=neopyxel.NeopyxelRelay()# Add Striperelay.add_stripe(NUMPIXELS=30,# Number of pixels of the stripePIN=5)# Digital pin to which the stripe is connected# Set the color of pixel (led) 15 to whitewhite=(255,255,255)relay.set_pixel_color(pixel_number=15,color=white)# Update pixel displayrelay.show()

简单效果执行:

importsysimportneopyxelfromneopyxelimporteffects# Instantiate NeopyxelRelay (no arguments are needed, but the COMPORT can be specified in case the detection fails)relay=neopyxel.NeopyxelRelay()# Add Striperelay.add_stripe(NUMPIXELS=30,# Number of pixels of the stripePIN=5)# Digital pin to which the stripe is connected# Execute Effecttry:relay.execute_effect(effects.Fireplace)exceptKeyboardInterrupt:# Try/Except is employed here to properly terminate effect thread on Ctrl+Crelay.stop_effect()relay.flush_stripes()print("Ctrl+C pressed...exit")sys.exit(1)

效果和转换配置与执行

importsysimportneopyxelfromneopyxelimporteffectsfromneopyxelimporttrasitions# Instantiate NeopyxelRelay (no arguments are needed, but the COMPORT can be specified in case the detection fails)relay=neopyxel.NeopyxelRelay()# Add Striperelay.add_stripe(NUMPIXELS=30,# Number of pixels of the stripePIN=5)# Digital pin to which the stripe is connected# Execute Effectambar=(240,80,30)try:relay.execute_effect(EffectClass=effects.SteadyColor,color=ambar,# SteadyColor effect admits color argumentStartTransition=transitions.expand.FromCenter,# These transitions can be usedStopTransition=transitions.expand.FromBorders# by any effects)exceptKeyboardInterrupt:# Try/Except is employed here to properly terminate effect thread on Ctrl+Crelay.stop_effect()relay.flush_stripes()print("Ctrl+C pressed...exit")sys.exit(1)

贡献

欢迎拉取请求。对于重大变化,请先打开一个问题,讨论您希望更改的内容。在

许可证

GPLv3

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java爬虫获取外部网站搜索结果   java Bluestack未连接到eclipse   java如何从ConstraintViolationException Hibernamte获取数据库字段名   HttpResponse HttpResponse=httpClient引发java运行时错误。执行(httpPost);   Jama中矩阵的java点积和叉积   java有什么方法可以唯一地识别可扩展设备吗?   java我需要用*来写我的名字,但我不断遇到一个错误,我对编码很陌生   java变量是在内部类中访问的。需要被宣布为最终决定。但我不想宣布最终结果   java如何缩短base64图像字符串,Android?   JavaSpringMVC:计划方法不自动触发   图形学习Java 2D API的好资源是什么?   如何在java中对方法进行排队   java JavaFX多行   java Selenium无法在[链接]上找到基于CSS元素的密码字段元素http://www.cartasi.it/gtwpages/index.jsp   Java中的equals()和hashCode()契约   软删除情况下的java Hibernate二级缓存   java为什么这段代码要两次调用这些方法?