arduino/Mixly WS2812点阵屏,FASTLED库学习

前言

关于WS2812的控制,主要有二个库,一个是FastLED库,另一个是Adafruit_NeoPixel库,Adafruit_NeoPixel这个库实测能控制的最大数量是600颗,超过630颗就不能控制了,这个库的优点是需要的内存小,uno的内存完全可以控制,FastLED这个需要的内存比较大,我是打算控制1024个灯珠,但是uno的内存就完全不够了,换了mega2560才行

arduino/Mixly WS2812点阵屏,FASTLED库学习_第1张图片

 

点亮LED

完整代码

#include "FastLED.h"            // 此示例程序需要使用FastLED库
 
#define NUM_LEDS 1024            // LED灯珠数量
#define DATA_PIN A0              // Arduino输出控制信号引脚
#define LED_TYPE WS2812         // LED灯带型号
#define COLOR_ORDER GRB         // RGB灯珠中红色、绿色、蓝色LED的排列顺序
 
uint8_t max_bright = 120;       // LED亮度控制变量,可使用数值为 0 ~ 255, 数值越大则光带亮度越高
 
CRGB leds[NUM_LEDS];            // 建立光带leds
 
void setup() { 
  LEDS.addLeds(leds, NUM_LEDS);  // 初始化光带 
  FastLED.setBrightness(max_bright);                            // 设置光带亮度
}
 
void loop() { 
   for (int i = 0; i <= 1023; i = i + (1)) {
    leds[i] = CRGB::Green;          // 设置光带中灯珠颜色为绿色,leds[0]为第一个灯珠,leds[1]为第二个灯珠
  }
  FastLED.show();                // 更新LED色彩
}

效果

arduino/Mixly WS2812点阵屏,FASTLED库学习_第2张图片

 其中颜色的表示有二种

设置颜色方法一

leds[i] = CRGB::Green;

这种是直接设置颜色,CRGB::Green就是绿色,但是绿色的深度这些是没办法调的,比如你要G值125的绿色,那这种办法是不能实现的。

这种办法的颜色值一共有以下几种:由于我的四个8*32的点阵之间有色差,所以这里只用一块8*32的点阵来演示。

CRGB::AliceBlue效果

arduino/Mixly WS2812点阵屏,FASTLED库学习_第3张图片

 CRGB::Amethyst效果

arduino/Mixly WS2812点阵屏,FASTLED库学习_第4张图片

CRGB::Brown效果

arduino/Mixly WS2812点阵屏,FASTLED库学习_第5张图片 

 其他的就不测试了,总共有以下几种

CRGB::AliceBlue
CRGB::Amethyst
CRGB::AntiqueWhite
CRGB::Aqua
CRGB::Aquamarine
CRGB::Azure
CRGB::Beige
CRGB::Bisque
CRGB::Black
CRGB::BlanchedAlmond
CRGB::Blue
CRGB::BlueViolet
CRGB::Brown
CRGB::BurlyWood
CRGB::CadetBlue
CRGB::Chartreuse
CRGB::Chocolate
CRGB::Coral
CRGB::CornflowerBlue
CRGB::Cornsilk
CRGB::Crimson
CRGB::Cyan
CRGB::DarkBlue
CRGB::DarkCyan
CRGB::DarkGoldenrod
CRGB::DarkGray
CRGB::DarkGreen
CRGB::DarkKhaki
CRGB::DarkMagenta
CRGB::DarkOliveGreen
CRGB::DarkOrange
CRGB::DarkOrchid
CRGB::DarkRed
CRGB::DarkSalmon
CRGB::DarkSeaGreen
CRGB::DarkSlateBlue
CRGB::DarkSlateGray
CRGB::DarkTurquoise
CRGB::DarkViolet
CRGB::DeepPink
CRGB::DeepSkyBlue
CRGB::DimGray
CRGB::DodgerBlue
CRGB::FireBrick
CRGB::FloralWhite
CRGB::ForestGreen
CRGB::Fuchsia
CRGB::Gainsboro
CRGB::GhostWhite
CRGB::Gold
CRGB::Goldenrod
CRGB::Gray
CRGB::Green
CRGB::GreenYellow
CRGB::Honeydew
CRGB::HotPink
CRGB::IndianRed
CRGB::Indigo
CRGB::Ivory
CRGB::Khaki
CRGB::Lavender
CRGB::LavenderBlush
CRGB::LawnGreen
CRGB::LemonChiffon
CRGB::LightBlue
CRGB::LightCoral
CRGB::LightCyan
CRGB::LightGoldenrodYellow
CRGB::LightGreen
CRGB::LightGrey
CRGB::LightPink
CRGB::LightSalmon
CRGB::LightSeaGreen
CRGB::LightSkyBlue
CRGB::LightSlateGray
CRGB::LightSteelBlue
CRGB::LightYellow
CRGB::Lime
CRGB::LimeGreen
CRGB::Linen
CRGB::Magenta
CRGB::Maroon
CRGB::MediumAquamarine
CRGB::MediumBlue
CRGB::MediumOrchid
CRGB::MediumPurple
CRGB::MediumSeaGreen
CRGB::MediumSlateBlue
CRGB::MediumSpringGreen
CRGB::MediumTurquoise
CRGB::MediumVioletRed
CRGB::MidnightBlue
CRGB::MintCream
CRGB::MistyRose
CRGB::Moccasin
CRGB::NavajoWhite
CRGB::Navy
CRGB::OldLace
CRGB::Olive
CRGB::OliveDrab
CRGB::Orange
CRGB::OrangeRed
CRGB::Orchid
CRGB::PaleGoldenrod
CRGB::PaleGreen
CRGB::PaleTurquoise
CRGB::PaleVioletRed
CRGB::PapayaWhip
CRGB::PeachPuff
CRGB::Peru
CRGB::Pink
CRGB::Plaid
CRGB::Plum
CRGB::PowderBlue
CRGB::Purple
CRGB::Red
CRGB::RosyBrown
CRGB::RoyalBlue
CRGB::SaddleBrown
CRGB::Salmon
CRGB::SandyBrown
CRGB::SeaGreen
CRGB::Seashell
CRGB::Sienna
CRGB::Silver
CRGB::SkyBlue
CRGB::SlateBlue
CRGB::SlateGray
CRGB::Snow
CRGB::SpringGreen
CRGB::SteelBlue
CRGB::Tan
CRGB::Teal
CRGB::Thistle
CRGB::Tomato
CRGB::Turquoise
CRGB::Violet
CRGB::Wheat
CRGB::White
CRGB::WhiteSmoke
CRGB::Yellow
CRGB::YellowGreen

设置颜色方法二

leds[i] = CRGB (0,255,0);

这种办法是直接设置RGB值,leds[i] = CRGB (0,255,0);从左到右分别是R值,G值,B值

效果

arduino/Mixly WS2812点阵屏,FASTLED库学习_第6张图片

 fillSolid将光带设置为同一颜色

fill_solid(leds, 30, CRGB::Red)

参数主要有个,第一个是从哪一个灯开始,第二个是往后取多少个灯,第三个是颜色

fill_solid(leds, 30, CRGB::Red)的效果

arduino/Mixly WS2812点阵屏,FASTLED库学习_第7张图片

和for循环的效果类似

fill_solid(leds+5, 30, CRGB::Red);

 fill_solid(leds+5, 30, CRGB::Red);的意思是从第六个灯开始,往后数30个LED,点亮为红色

未完待续!后面会加上显示图片,显示汉字,显示字符,滚动等效果

你可能感兴趣的:(Mixly与Arduino,c语言,开发语言,arduino)