“4RGB LED”的版本间的差异

来自Labplus盛思维基百科
跳转至: 导航搜索
Arduino示例
Arduino示例
第27行: 第27行:
 
Arduino库 Adafruit NeoPixel [http://wiki.labplus.cn/images/d/d0/Adafruit_NeoPixel-master.zip 点击下载]
 
Arduino库 Adafruit NeoPixel [http://wiki.labplus.cn/images/d/d0/Adafruit_NeoPixel-master.zip 点击下载]
  
<source lang="arduino">
+
<pre style="color:blue">
int LED_PIN=13;
+
// 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 setup () {                    // 初始化副程式,程式起始時僅執行一次
 
    pinMode (LED_PIN, OUTPUT);    // 以數位輸出方式啟用Pin13
 
 
}
 
}
  
void loop () {                     // loop副程式,重複不斷執行
+
void loop() {
    digitalWrite (LED_PIN, HIGH); // 打開LED(發光二極管)
+
for(uint16_t num1=0;num1<PIXEL_COUNT;num1++)
    delay (1000);                 // 等待一秒,delay內含數值1000,代表延遲1000毫秒,即一秒。
+
{
    digitalWrite (LED_PIN, LOW);  // 關閉LED
+
strip.setPixelColor(num1,255,0,0);  //设置红色
    delay (1000);                 // 等待一秒
+
}
}                                 // loop副程式結束
+
strip.show();   //显示
</source>
+
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> ===

2018年1月8日 (一) 10:29的版本

黑色传感器最终版12.20-13.png

概述

单板级联4颗RGB灯珠,采用LED专用主控芯片WS2812,支持单总线控制,仅需一根管脚即可控制所有LED,并且模块支持级联控制,可以多个模块同时控制,不占用管脚资源。可实现256级亮度显示,16777216种颜色的全真色彩显示颜色。

技术参数

  • 工作电压:VCC 3.3-5V
  • 通讯方式:单总线控制
  • 功 率:0.3W/颗
  • 级联4颗灯珠
  • 灰度等级:256级
  • 16777216种颜色的全真色彩
  • 模块尺寸:24x46x7.5mm

引脚定义

VCC 电源
NC 空脚
DI 控制数据信号输入
GND

使用教程

Arduino示例

Arduino库 Adafruit NeoPixel 点击下载

// 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示例

连接示意图

RGB连接图.jpg
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)

   

图形化示例