1 单纯控制颜色
接线
Arduino Uno 共阳三色雾状LED灯
Pin 9 <----------> 红
Pin 10 <----------> 绿
Pin 11 <----------> 蓝
3.3v <----------> 共阳
注意(5v怕烧灯,不过可以加200欧姆的电阻就可以了)
<span style="font-family:'Microsoft YaHei';">#define led_red 9 //Pin 9 连接上 led的红色引脚
#define led_green 10
#define led_blue 11 void setup() {
pinMode(led_red,OUTPUT); //设置为输出模式
pinMode(led_green,OUTPUT);
pinMode(led_blue,OUTPUT); analogWrite(led_red,255); //首先,先把所有的灯都关闭
analogWrite(led_green,255); //可以随意设置开启关闭哪些灯,搭配出不同组合有不同颜色
analogWrite(led_blue,255);
} void loop() {
// put your main code here, to run repeatedly: for(int i=200;i>0;i--) //渐亮
{
analogWrite(led_red,i); //慢慢开启红色和绿色会搭配出黄色
analogWrite(led_green,i);
analogWrite(led_blue,255);
delay(10);
} for(int i=0;i<200;i++) //渐灭
{
analogWrite(led_red,255); //慢慢关闭绿色和蓝色会搭配出较鲜艳的蓝色
analogWrite(led_green,i);
analogWrite(led_blue,i);
delay(10);
} }</span>
2 彩灯
https://www.jianshu.com/p/2fedeab3b9fe
-
Arduino UNO 开发板
WS2812 5050 RGB LED灯条
下载WS2812 Arduino 驱动库:Adafruit_NeoPixel(https://github.com/adafruit/Adafruit_NeoPixel)
4. 打开Arduino IDE,选择File->Example->Adafruit_NeoPixel->stand test.
5. 选择相应的板信息:
2.1
http://ruten-proteus.blogspot.com/2014/06/arduino-ws2812b-meteor-light.html