使用RGB数值表达颜色 |
使用颜色名称表达颜色 |
使用RGB数值表达颜色
语法
CRGB (rVal,gVal,bVal);
或
CRGB RGBcolorName(rVal,gVal,bVal);
参数
rVal – 红色数值
gVal – 绿色数值
bVal – 蓝色数值
备注
RGBcolorName.r 代表红色数值。可对其进行操作。
示例程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
/* * FastLED-RGB颜色表达方法 * CRGB myRGBcolor(50,0,50); * myRGBcolor.r代表红色数值。可对其进行操作 * 太极创客 www.taichi-maker.com * 2018-03-15 */ #include "FastLED.h" // 此示例程序需要使用FastLED库 #define NUM_LEDS 30 // LED灯珠数量 #define LED_DT 9 // Arduino输出控制信号引脚 #define LED_TYPE WS2812 // LED灯带型号 #define COLOR_ORDER GRB // RGB灯珠中红色、绿色、蓝色LED的排列顺序 uint8_t max_bright = 128; // LED亮度控制变量,可使用数值为 0 ~ 255, 数值越大则光带亮度越高 CRGB leds[NUM_LEDS]; // 建立光带leds CRGB myRGBcolor(50,0,50); //myRGBcolor(红色数值,绿色数值,蓝色数值) void setup() { LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // 初始化光带 FastLED.setBrightness(max_bright); // 设置光带亮度 set_max_power_in_volts_and_milliamps(5, 500); // 光带电源管理(设置光带5伏特,500mA) } void loop () { // 演示如何使用.r方法改变CRGB颜色的某一个数值 myRGBcolor.r++; //修改RGB定义颜色的单一数值 //myRGBcolor.r为myRGBcolor的红色颜色数值 fill_solid(leds, NUM_LEDS, myRGBcolor); FastLED.show(); delay(10); } // loop() |
使用颜色名称表达颜色
语法
CRGB::colorName
参数
colorName:颜色名称(如,Red、Green等)
示例程序
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
/* * blinkOne * 太极创客 http://www.taichi-maker.com/ * 03/01/2018 * * =====================功能说明===================== * 使用Arduino Uno开发板控制WS2812光带一个灯珠的闪烁。 * * 本示例程序需要Arduino第三方库FastLED。如有需要,可通过以下链接下载该库: * http://www.taichi-maker.com/homepage/download/#library-download * * 如需了解如何为Arduino IDE安装第三方库,请参见以下链接地址的视频教程: * http://www.taichi-maker.com/homepage/reference-index/arduino-library-index/install-arduino-library/ * * =====================电路连接====================== * 此示例程序中,Arduino输出控制信号引脚为9号引脚。 * * 如需获得详细电路连接说明图,请参阅太极创客网站中 * 有关WS2812 LED光带方面的相关内容,太极创客网站地址: * * http://WWW.TAICHI-MAKER.COM * * 此示例程序为配合太极创客制作的 * 《零基础入门学用ARDUINO教程-智能应用篇》使用 */ #include "FastLED.h" // 此示例程序需要使用FastLED库 #define NUM_LEDS 30 // LED灯珠数量 #define DATA_PIN 9 // Arduino输出控制信号引脚 #define LED_TYPE WS2812 // LED灯带型号 #define COLOR_ORDER GRB // RGB灯珠中红色、绿色、蓝色LED的排列顺序 uint8_t max_bright = 128; // LED亮度控制变量,可使用数值为 0 ~ 255, 数值越大则光带亮度越高 CRGB leds[NUM_LEDS]; // 建立光带leds void setup() { Serial.begin(9600); // 启动串行通讯 delay(1000); // 稳定性等待 LEDS.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS); // 初始化光带 FastLED.setBrightness(max_bright); // 设置光带亮度 } void loop() { leds[0] = CRGB::Red; // 设置光带中第一个灯珠颜色为红色,leds[0]为第一个灯珠,leds[1]为第二个灯珠 FastLED.show(); // 更新LED色彩 delay(50); // 等待500毫秒 } |
FastLED颜色名称列表:
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