“RGB LED”的版本间的差异
来自Labplus盛思维基百科
Tangliufeng(讨论 | 贡献) (→Arduino示例) |
(→使用教程) |
||
(未显示3个用户的16个中间版本) | |||
第3行: | 第3行: | ||
采用LED专用主控芯片WS2812,支持单总线控制,仅需一根管脚即可控制所有LED,并且模块支持级联控制,可以多个模块同时控制,不占用管脚资源。可实现256级亮度显示,16777216种颜色的全真色彩显示颜色。 | 采用LED专用主控芯片WS2812,支持单总线控制,仅需一根管脚即可控制所有LED,并且模块支持级联控制,可以多个模块同时控制,不占用管脚资源。可实现256级亮度显示,16777216种颜色的全真色彩显示颜色。 | ||
== 技术参数 == | == 技术参数 == | ||
− | * | + | * 工作电压:VCC 3.3-5V |
* 通讯方式:单总线控制 | * 通讯方式:单总线控制 | ||
* 功 率:0.3W/颗 | * 功 率:0.3W/颗 | ||
第36行: | 第36行: | ||
当多个模块需要级联时,把上一个模块的DO连接至下个模块的DI! | 当多个模块需要级联时,把上一个模块的DO连接至下个模块的DI! | ||
== 使用教程 == | == 使用教程 == | ||
− | === < | + | === <font size="3">掌控板</font> === |
+ | {| | ||
+ | |- | ||
+ | | [[文件:RGB.png |900px|居中|无框]] | ||
+ | |} | ||
+ | |||
=== <small>Arduino示例</small> === | === <small>Arduino示例</small> === | ||
− | + | [http://wiki.labplus.cn/images/d/d0/Adafruit_NeoPixel-master.zip RGB LED库文件下载] | |
+ | |||
+ | <pre style="color:blue"> | ||
+ | //程序功能:依次按照红绿蓝点亮LED灯// | ||
+ | // This is a demonstration on how to use an input device to trigger changes on your neo pixels. | ||
+ | // You should wire a momentary push button to connect from ground to a digital IO pin. When you | ||
+ | // press the button it will change to a new pixel animation. Note that you need to press the | ||
+ | // button once to start the first animation! | ||
+ | |||
+ | #include "Adafruit_NeoPixel.h" | ||
+ | |||
+ | |||
+ | |||
+ | #define PIXEL_PIN 7 // Digital IO pin connected to the NeoPixels. | ||
+ | |||
+ | #define PIXEL_COUNT 10 //级联数量 | ||
+ | |||
+ | // Parameter 1 = number of pixels in strip, neopixel stick has 8 | ||
+ | // Parameter 2 = pin number (most are valid) | ||
+ | // Parameter 3 = pixel type flags, add together as needed: | ||
+ | // NEO_RGB Pixels are wired for RGB bitstream | ||
+ | // NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick | ||
+ | // NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels) | ||
+ | // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick | ||
+ | Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); | ||
+ | |||
+ | |||
+ | |||
+ | void setup() { | ||
+ | |||
+ | strip.setBrightness(50); //调亮度 | ||
+ | strip.begin(); | ||
+ | strip.show(); // Initialize all pixels to 'off' | ||
+ | |||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | for(uint16_t num1=0;num1<PIXEL_COUNT;num1++) | ||
+ | { | ||
+ | strip.setPixelColor(num1,255,0,0); //设置红色 | ||
+ | } | ||
+ | strip.show(); //显示 | ||
+ | delay(500); | ||
+ | for(uint16_t num1=0;num1<PIXEL_COUNT;num1++) | ||
+ | { | ||
+ | strip.setPixelColor(num1,0,255,0); //设置绿色 | ||
+ | } | ||
+ | strip.show(); //显示 | ||
+ | delay(500); | ||
+ | for(uint16_t num1=0;num1<PIXEL_COUNT;num1++) | ||
+ | { | ||
+ | strip.setPixelColor(num1,0,0,255); //设置蓝色 | ||
+ | } | ||
+ | strip.show(); //显示 | ||
+ | delay(500); | ||
+ | |||
+ | } | ||
+ | |||
+ | </pre> | ||
=== <small>MicroPython示例</small> === | === <small>MicroPython示例</small> === | ||
第66行: | 第129行: | ||
</pre> | </pre> | ||
+ | === <small>图形化示例</small> === | ||
+ | {| | ||
+ | |- | ||
+ | |注意:彩灯位置是从"0"开始计算,第一个为np[0] | ||
+ | |- | ||
+ | |程序功能:让RGB LED灯依次发出红绿蓝三种颜色的光 | ||
+ | |- | ||
+ | |[[文件:RGB led.png|900px|无框|左]] | ||
+ | |} | ||
− | === <small> | + | == 版本历史记录 == |
+ | |||
+ | {| border="1" cellspacing="0" align="left" cellpadding="0" width="60%" style="text-align:center;" | ||
+ | |- style="text-align:center;background-color:#6fa8dc;color:#fffff;" | ||
+ | !width="10%"|Version !!width="15%"| Date !! Note <small>[+]新增[-]删除[^]修复</small> | ||
+ | |- | ||
+ | | V2.0 || || style="text-align:left"| | ||
+ | |} |
2020年6月30日 (二) 16:46的最新版本
概述
采用LED专用主控芯片WS2812,支持单总线控制,仅需一根管脚即可控制所有LED,并且模块支持级联控制,可以多个模块同时控制,不占用管脚资源。可实现256级亮度显示,16777216种颜色的全真色彩显示颜色。
技术参数
- 工作电压:VCC 3.3-5V
- 通讯方式:单总线控制
- 功 率:0.3W/颗
- 灰度等级:256级
- 16777216种颜色的全真色彩
- 支持级联控制
- 模块尺寸:24x46x7.5mm
引脚定义
VCC | 电源 |
NC | 空脚 |
DI | 控制数据信号输入 |
GND | 地 |
VCC | 电源 |
NC | 空脚 |
DO | 控制数据信号输出 |
GND | 地 |
当多个模块需要级联时,把上一个模块的DO连接至下个模块的DI!
使用教程
掌控板
Arduino示例
//程序功能:依次按照红绿蓝点亮LED灯// // This is a demonstration on how to use an input device to trigger changes on your neo pixels. // You should wire a momentary push button to connect from ground to a digital IO pin. When you // press the button it will change to a new pixel animation. Note that you need to press the // button once to start the first animation! #include "Adafruit_NeoPixel.h" #define PIXEL_PIN 7 // Digital IO pin connected to the NeoPixels. #define PIXEL_COUNT 10 //级联数量 // Parameter 1 = number of pixels in strip, neopixel stick has 8 // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_RGB Pixels are wired for RGB bitstream // NEO_GRB Pixels are wired for GRB bitstream, correct for neopixel stick // NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels) // NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); void setup() { strip.setBrightness(50); //调亮度 strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { for(uint16_t num1=0;num1<PIXEL_COUNT;num1++) { strip.setPixelColor(num1,255,0,0); //设置红色 } strip.show(); //显示 delay(500); for(uint16_t num1=0;num1<PIXEL_COUNT;num1++) { strip.setPixelColor(num1,0,255,0); //设置绿色 } strip.show(); //显示 delay(500); for(uint16_t num1=0;num1<PIXEL_COUNT;num1++) { strip.setPixelColor(num1,0,0,255); //设置蓝色 } strip.show(); //显示 delay(500); }
MicroPython示例
from microbit import * import neopixel import math display.off() np=neopixel.NeoPixel(pin0,4) #pin0为控制引脚,级联4个RGB while True: for i in range(4): np[i]= (255,0,0) #设置4颗灯珠显示颜色,颜色为红 np.show() #刷新显示颜色 for i in range(4): np[i]= (0,255,0) #设置4颗灯珠显示颜色,颜色为绿 sleep(1000) np.show() #刷新显示颜色 for i in range(4): np[i]= (0,0,255) #设置4颗灯珠显示颜色,颜色为蓝 sleep(1000) np.show() #刷新显示颜色 sleep(1000)
图形化示例
注意:彩灯位置是从"0"开始计算,第一个为np[0] |
程序功能:让RGB LED灯依次发出红绿蓝三种颜色的光 |
版本历史记录
Version | Date | Note [+]新增[-]删除[^]修复 |
---|---|---|
V2.0 |