04. fastLED像素参考(颜色设置详解)

fastLED像素参考

原文

Overview 概述

There’s two main pixel types in the library - the CRGB class and the CHSV class. CHSV objects have to be converted to CRGB objects before they can be written out. You can also write CHSV objects into the CRGB array and have the translation occur as necessary.
库中有两种主要的像素类型 - CRGB 类和 CHSV 类。 CHSV 对象必须先转换为 CRGB 对象,然后才能写出它们。您还可以将 CHSV 对象写入 CRGB 数组,并根据需要进行转换。

CRGB Reference CRGB 参考

A “CRGB” is an object representing a color in RGB color space. It contains simply:
“CRGB”是表示RGB色彩空间中颜色的对象。它包含以下内容:

  • a one byte value (0-255) representing the amount of red,
    一个字节值 (0-255) 表示红色的数量,
  • a one byte value (0-255) representing the amount of green,
    一个字节值 (0-255) 表示绿色的数量,
  • a one byte value (0-255) representing the amount of blue in a given color.
    一个字节值 (0-255),表示给定颜色中的蓝色量。

Typically, when using this library, each LED strip is represented as an array of CRGB colors, one color for each LED pixel.
通常,使用此库时,每个 LED 灯条都表示为 CRGB 颜色数组,每个 LED 像素对应一种颜色。

  #define NUM_LEDS 160CRGB leds[ NUM_LEDS ];

For more general information on what the RGB color space is, see http://en.wikipedia.org/wiki/RGB_color_model
有关 RGB 色彩空间的更多一般信息,请参阅 http://en.wikipedia.org/wiki/RGB_color_model

Data Members 数据成员

CRGB has three one-byte data members, each representing one of the three red, green, and blue color channels of the color. There is more than one way to access the RGB data; each of these following examples does exactly the same thing:
CRGB 有三个单字节数据成员,每个成员代表颜色的三个红色、绿色和蓝色通道之一。访问RGB数据的方法不止一种;以下每个示例都执行完全相同的操作:

  // The three color channel values can be referred to as "red", "green", and "blue"...leds[i].red   = 50;leds[i].green = 100;leds[i].blue  = 150;// ...or, using the shorter synonyms "r", "g", and "b"...leds[i].r = 50;leds[i].g = 100;leds[i].b = 150;// ...or as members of a three-element array:leds[i][0] = 50;  // redleds[i][1] = 100; // greenleds[i][2] = 150; // blue

Direct Access 直接访问

You are welcome, and invited, to directly access the underlying memory of this object if that suits your needs. That is to say, there is no “CRGB::setRed( myRedValue )” method; instead you just directly store ‘myRedValue’ into the “.red” data member on the object. All of the methods on the CRGB class expect this, and will continue to operate normally. This is a bit unusual for a C++ class, but in a microcontroller environment this can be critical to maintain performance.
如果适合您的需求,欢迎您直接访问此对象的底层内存。也就是说,没有“CRGB::setRed( myRedValue )”方法;相反,您只需将“myRedValue”直接存储到对象上的“.red”数据成员中即可。CRGB 类上的所有方法都期望这一点,并将继续正常运行。这对于 C++ 类来说有点不寻常,但在微控制器环境中,这对于保持性能至关重要。

The CRGB object “is trivially copyable”, meaning that it can be copied from one place in memory to another and still function normally.
CRGB 对象“是微不足道的可复制的”,这意味着它可以从内存中的一个位置复制到另一个位置,并且仍然可以正常运行。

Methods 方法

In addition to simply providing data storage for the RGB colors of each LED pixel, the CRGB class also provides several useful methods color-manipulation, some of which are implemented in assembly language for speed and compactness. Often using the class methods described here is faster and smaller than hand-written C/C++ code to achieve the same thing.
除了简单地为每个 LED 像素的 RGB 颜色提供数据存储外,CRGB 类还提供了几种有用的颜色处理方法,其中一些是用汇编语言实现的,以提高速度和紧凑性。通常使用这里描述的类方法比手写的 C/C++ 代码更快、更小来实现同样的事情。

Setting RGB Colors 设置 RGB 颜色

CRGB colors can be set by assigning values to the individual red, green, and blue channels. In addition, CRGB colors can be set a number of other ways which are often more convenient and compact. The two pieces of code below perform the exact same function.
可以通过为各个红色、绿色和蓝色通道分配值来设置 CRGB 颜色。此外,CRGB颜色还可以通过许多其他方式进行设置,这些方式通常更方便,更紧凑。下面的两段代码执行完全相同的功能。

  //Example 1: set color from red, green, and blue components individuallyleds[i].red =    50;leds[i].green = 100;leds[i].blue =  150;//Example 2: set color from red, green, and blue components all at onceleds[i] = CRGB( 50, 100, 150);

Some performance-minded programmers may be concerned that using the ‘high level’, ‘object-oriented’ code in the second example comes with a penalty in speed or code size. However, this is simply not the case; the examples above generate literally identical machine code, taking up exactly the same amount of program memory, and executing in exactly the same amount of time. Given that, the choice of which way to write the code, then, is entirely a matter of personal taste and style. All other things being equal, the simpler, higher-level, more object-oriented code is generally recommended.
一些注重性能的程序员可能会担心,在第二个示例中使用“高级”、“面向对象”的代码会降低速度或代码大小。然而,事实并非如此。上面的例子生成了完全相同的机器代码,占用了完全相同的程序内存量,并在完全相同的时间内执行。鉴于此,选择哪种方式编写代码完全是个人品味和风格的问题。在所有其他条件相同的情况下,通常建议使用更简单、更高级别、更面向对象的代码。

Here are the other high-level ways to set a CRGB color in one step:
以下是一步设置 CRGB 颜色的其他高级方法:

  // Example 3: set color via 'hex color code' (0xRRGGBB)leds[i] = 0xFF007F;// Example 4: set color via any named HTML web colorleds[i] = CRGB::HotPink;// Example 5: set color via setRGBleds[i].setRGB( 50, 100, 150);

Again, for the performance-minded programmer, it’s worth noting that all of the examples above compile down into exactly the same number of machine instructions. Choose the method that makes your code the simplest, most clear, and easiest to read and modify.
同样,对于注重性能的程序员来说,值得注意的是,上面的所有示例都编译成完全相同数量的机器指令。选择使代码最简单、最清晰、最易于阅读和修改的方法。

Colors can also be copied from one CRGB to another:
颜色也可以从一个 CRGB 复制到另一个 CRGB:

  // Copy the CRGB color from one pixel to anotherleds[i] = leds[j];

If you are copying a large number of colors from one (part of an) array to another, the standard library function memmove can be used to perform a bulk transfer; the CRGB object “is trivially copyable”.
如果要将大量颜色从一个(部分)数组复制到另一个数组,则可以使用标准库函数 memmove 来执行批量传输;CRGB 对象“是微不足道的可复制的”。

  // Copy ten led colors from leds[src .. src+9] to leds[dest .. dest+9]memmove( &leds[dest], &leds[src], 10 * sizeof( CRGB) );

Performance-minded programmers using AVR/ATmega MCUs to move large number of colors in this way may wish to use the alternative “memmove8” library function, as it is measurably faster than the standard libc “memmove”.
使用AVR/ATmega MCU以这种方式移动大量颜色,具有性能意识的程序员可能希望使用替代的“memmove8”库函数,因为它比标准的libcmemmove”快得多。

Setting HSV Colors 设置 HSV 颜色

Introduction to HSV 单纯疱疹病毒简介

CRGB color objects use separate red, green, and blue channels internally to represent each composite color, as this is exactly the same way that multicolor LEDs do it: they have one red LED, one green LED, and one blue LED in each ‘pixel’. By mixing different amounts of red, green, and blue, thousands or millions of resultant colors can be displayed.
CRGB 颜色对象在内部使用单独的红色、绿色和蓝色通道来表示每种复合颜色,因为这与多色 LED 完全相同:它们在每个“像素”中有一个红色 LED、一个绿色 LED 和一个蓝色 LED。通过混合不同数量的红色、绿色和蓝色,可以显示数千或数百万种生成的颜色。

However, working with raw RGB values in your code can be awkward in some cases. For example, it is difficult to work express different tints and shades of a single color using just RGB values, and it can be particular daunting to describe a ‘color wash’ in RGB that cycles around a rainbow of hues while keeping a constant brightness.
但是,在某些情况下,在代码中使用原始 RGB 值可能会很尴尬。例如,仅使用 RGB 值很难表达单一颜色的不同色调和阴影,并且描述 RGB 中的“颜色洗涤”可能特别令人生畏,它围绕彩虹色调循环,同时保持恒定的亮度。

To simplify working with color in these ways, the library provides access to an alternate color model based on three different axes: Hue, Saturation, and Value (or ‘Brightness’). For a complete discussion of HSV color, see http://en.wikipedia.org/wiki/HSL_and_HSV , but briefly:
为了简化以这些方式处理颜色的过程,该库提供了对基于三个不同轴的备用颜色模型的访问:色相、饱和度和值(或“亮度”)。有关HSV颜色的完整讨论,请参阅 http://en.wikipedia.org/wiki/HSL_and_HSV,但简要介绍:

  • Hue is the ‘angle’ around a color wheel
    色相是色轮周围的“角度”
  • Saturation is how ‘rich’ (versus pale) the color is
    饱和度是颜色的“丰富”程度(相对于苍白)
  • Value is how ‘bright’ (versus dim) the color is
    值是颜色的“亮度”(相对于暗淡度)
HSV颜色简介

HSV(Hue, Saturation, Value)是根据颜色的直观特性由A. R. Smith在1978年创建的一种颜色表达方法。该方法中的三个参数分别是:色调(H),饱和度(S),明亮度(V)。

HSV参数

色调H

在这里插入图片描述

色调参数取值范围为0~255。如上图所示,从红色开始按逆时针方向计算。红色为0,绿色为85,蓝色为170。

饱和度S
饱和度S表示颜色接近光谱色的程度。取值范围为0~255,值越大,颜色越饱和(越接近本色)。值越小,颜色越接近白色。当数值为零时,颜色为白色。

亮度V
明亮度V表示颜色明亮的程度,取值范围为0~255。对于FastLED库来说,该数值越大,则控制光带的亮度越亮。反之数值越小,则控制光带的亮度越低。当数值为零时,光带完全熄灭。

In the library, the “hue” angle is represented as a one-byte value ranging from 0-255. It runs from red to orange, to yellow, to green, to aqua, to blue, to purple, to pink, and back to red. Here are the eight cardinal points of the hue cycle in the library, and their corresponding hue angle.
在库中,“色调”角度表示为一个字节值,范围为 0-255。它从红色到橙色,到黄色,到绿色,到浅绿色,到蓝色,到紫色,到粉红色,再回到红色。以下是库中色相循环的八个基点,以及它们对应的色相角度。

FastLED Rainbow color map Click here for full-size chart.
点击这里查看全尺寸图表。

  • Red (0…) "HUE_RED

  • Orange (32…) “HUE_ORANGE”

  • Yellow (64…) “HUE_YELLOW”

  • Green (96…) “HUE_GREEN”

  • Aqua (128…) “HUE_AQUA”

  • Blue (160…) “HUE_BLUE”

  • Purple (192…) “HUE_PURPLE”

  • Pink(224…) “HUE_PINK”

Often in other HSV color spaces, hue is represented as an angle from 0-360 degrees. But for compactness, efficiency, and speed, this library represents hue as a single-byte number from 0-255. There’s a full wiki page how FastLED deals with HSV colors here.
通常在其他 HSV 颜色空间中,色调表示为 0-360 度的角度。但为了紧凑、高效和速度,该库将色调表示为 0-255 之间的单字节数。这里有一个完整的 wiki 页面,介绍了 FastLED 如何处理 HSV 颜色。

“saturation” is a one-byte value ranging from 0-255, where 255 means “completely saturated, pure color”, 128 means “half-saturated, a light, pale color”, and 0 means “completely de-saturated: plain white”.
“饱和度”是一个介于 0-255 之间的单字节值,其中 255 表示“完全饱和,纯色”,128 表示“半饱和,浅色,浅色”,0 表示“完全不饱和:纯白色”。

“value” is a one-byte value ranging from 0-255 representing brightness, where 255 means “completely bright, fully lit”, 128 means “somewhat dimmed, only half-lit”, and zero means “completely dark: black.”
“value”是一个字节值,范围从 0-255 表示亮度,其中 255 表示“完全明亮,完全照亮”,128 表示“有点暗,只有半亮”,0 表示“完全黑暗:黑色”。

The CHSV Object CHSV 对象

In the library, a CHSV object is used to represent a color in HSV color space. The CHSV object has the three one-byte data members that you might expect:
在库中,CHSV 对象用于表示 HSV 颜色空间中的颜色。CHSV 对象具有您可能期望的三个单字节数据成员:

  • hue (or ‘h’) 色调(或“h”)
  • saturation (or ‘sat’, or just ‘s’)
    饱和度(或“sat”,或简称“s”)
  • value (or ‘val’, or just ‘v’) These can be directly manipulated in the same way that red, green, and blue can be on a CRGB object. CHSV objects are also “trivially copyable”.
    value(或“val”,或简称“v”) 这些可以直接操作,就像红色、绿色和蓝色可以放在 CRGB 对象上一样。CHSV 对象也是“微不足道的可复制的”。
  // Set up a CHSV colorCHSV paleBlue( 160, 128, 255);// Now...//   paleBlue.hue == 160//   paleBlue.sat == 128//   paleBlue.val == 255

Automatic Color Conversion 自动颜色转换

The library provides fast, efficient methods for converting a CHSV color into a CRGB color. Many of these are automatic and require no explicit code.
该库提供了将 CHSV 颜色转换为 CRGB 颜色的快速、有效的方法。其中许多是自动的,不需要显式代码。

For example, to set an led to a color specified in HSV, you can simply assign a CHSV color to a CRGB color:
例如,要将 LED 设置为 HSV 中指定的颜色,您只需将 CHSV 颜色分配给 CRGB 颜色:

  // Set color from Hue, Saturation, and Value.  // Conversion to RGB is automatic.leds[i] = CHSV( 160, 255, 255);// alternate syntaxleds[i].setHSV( 160, 255, 255);// set color to a pure, bright, fully saturated, hueleds[i].setHue( 160);

There is no conversion back from CRGB to CHSV provided with the library at this point.
此时,库中没有从 CRGB 转换回 CHSV。

Explicit Color Conversion 显式颜色转换

There are two different HSV color spaces: “spectrum” and “rainbow”, and they’re not exactly the same thing. Wikipedia has a good discussion here http://en.wikipedia.org/wiki/Rainbow#Number_of_colours_in_spectrum_or_rainbow but for purposes of the library, it can be summed up as follows:
有两种不同的 HSV 颜色空间:“光谱”和“彩虹”,它们并不完全相同。维基百科在这里有一个很好的讨论 http://en.wikipedia.org/wiki/Rainbow#Number_of_colours_in_spectrum_or_rainbow 但出于库的目的,它可以总结如下:

  • “Spectra” have barely any real yellow in them; the yellow band is incredibly narrow.
    “光谱”中几乎没有任何真正的黄色;黄色条带非常窄。
  • “Rainbows” have a band of yellow approximately as wide as the ‘orange’ and ‘green’ bands around it; the yellow range is easy to see.
    “彩虹”有一条黄色带,大约与它周围的“橙色”和“绿色”带一样宽;黄色范围很容易看到。

All of the automatic color conversions in the library use the “HSV Rainbow” color space, but through use of explicit color conversion routines, you can select to use the “HSV Spectrum” color space. There’s a full wiki page how FastLED deals with HSV colors here.
库中的所有自动颜色转换都使用“HSV Rainbow”色彩空间,但通过使用显式颜色转换例程,您可以选择使用“HSV Spectrum”色彩空间。这里有一个完整的 wiki 页面,介绍了 FastLED 如何处理 HSV 颜色。

The first explicit color conversion function is hsv2rgb_rainbow, which is used in the automatic color conversions:
第一个显式颜色转换函数是 hsv2rgb_rainbow,用于自动颜色转换:

  // HSV (Rainbow) to RGB color conversionCHSV hsv( 160, 255, 255); // pure blue in HSV Rainbow spaceCRGB rgb;hsv2rgb_rainbow( hsv, rgb);// rgb will now be (0, 0, 255)  -- pure blue as RGB

The HSV Spectrum color space has different cardinal points, and only six of them, which are correspondingly spread out further numerically. Here is the “Spectrum” color map that FastLED provides if you call hsv2rgb_spectrum explicitly:
HSV Spectrum 色彩空间具有不同的基点,其中只有六个基点,这些基点相应地在数字上进一步分布。以下是 FastLED 提供的“光谱”颜色图,如果您显式调用hsv2rgb_spectrum:FastLED Spectrum color map Click here for full-size chart.
点击这里查看全尺寸图表。

  • Red (0…) 红色 (0…)
  • Yellow (42…) 黄色 (42…)
  • Green (85…) 绿色 (85…)
  • Aqua (128…) 水 (128…)
  • Blue (171…) 蓝色 (171…)
  • Purple (213…) 紫色 (213…)

The hsv2rgb_spectrum conversion function’s API is identical to hsv2rgb_rainbow:
hsv2rgb_spectrum转换函数的 API 与 hsv2rgb_rainbow 相同:

  // HSV (Spectrum) to RGB color conversionCHSV hsv( 171, 255, 255); // pure blue in HSV Spectrum spaceCRGB rgb;hsv2rgb_spectrum( hsv, rgb);// rgb will now be (0, 0, 255)  -- pure blue as RGB

Why use the Spectrum color space, instead of Rainbow? The HSV Spectrum color space can be converted to RGB a little faster than the HSV Rainbow color space can be – but the results are not as good visually; what little yellow there is appears dim, and at lower brightnesses, almost brownish. So there is a trade-off between a few clock cycles and visual quality. In general, start with the Rainbow functions (or better yet, the automatic conversions), and drop down to the Spectrum functions only if you completely run out of speed.
为什么使用 Spectrum 色彩空间而不是 Rainbow?HSV Spectrum 色彩空间转换为 RGB 的速度比 HSV Rainbow 色彩空间快一点——但结果在视觉上并不那么好;那里的黄色看起来很暗淡,在较低的亮度下,几乎是褐色的。因此,在几个时钟周期和视觉质量之间需要权衡。通常,从 Rainbow 函数(或者更好的是自动转换)开始,只有在完全耗尽速度时才下拉到 Spectrum 函数。

Both color space conversion functions can also convert an array of CHSV colors to a corresponding array of CRGB colors:
这两个色彩空间转换函数还可以将 CHSV 颜色数组转换为相应的 CRGB 颜色数组:

  // Convert ten CHSV rainbow values to ten CRGB values;CHSV hsvs[10];CRGB leds[10];// (set hsv values here)hsv2rgb_rainbow( hsvs, leds, 10); // convert all

The function “hsv2rgb_spectrum” can also be called this way for bulk conversions.
函数“hsv2rgb_spectrum”也可以以这种方式调用以进行批量转换。

Comparing Colors 比较颜色

CRGB colors can be compared for exact matches using == and !=.
可以使用 == 和 != 比较 CRGB 颜色的完全匹配。

CRGB colors can be compared for relative light levels using <, >, <=, and =>. Note that this is a simple numeric comparison, and it will not always match the perceived brightness of the colors.
可以使用 <、>、<= 和 => 来比较相对光照水平的 CRGB 颜色。请注意,这是一个简单的数字比较,它并不总是与颜色的感知亮度相匹配。

Often it is useful to check if a color is completely ‘black’, or if it is ‘lit’ at all. You can do this by testing the color directly with ‘if’, or using it in any other boolean context.
通常,检查一种颜色是否完全“黑色”,或者它是否完全“点亮”是很有用的。您可以通过直接使用“if”测试颜色来做到这一点,或者在任何其他布尔上下文中使用它。

  // Test if a color is lit at all (versus pure black)if( leds[i] ) {/* it is somewhat lit (not pure black) */} else {/* it is completely black */}

Color Math 颜色数学

The library supports a rich set of ‘color math’ operations that you can perform on one or more colors. For example, if you wanted to add a little bit of red to an existing LED color, you could do this:
该库支持一组丰富的“颜色数学”运算,您可以对一种或多种颜色执行这些运算。例如,如果您想在现有的 LED 颜色中添加一点红色,您可以这样做:

  // Here's all that's needed to add "a little red" to an existing LED color:leds[i] += CRGB( 20, 0, 0);

That’s it. 就是这样。

If you’ve ever done this sort of thing by hand before, you may notice something missing: the check for the red channel overflowing past 255. Traditionally, you’ve probably had to do something like this:
如果你以前曾经手动做过这种事情,你可能会注意到缺少一些东西:检查溢出超过 255 的红色通道。传统上,您可能不得不做这样的事情:

  // Add a little red, the old way.uint16_t newRed;newRed = leds[i].r + 20;if( newRed > 255) newRed = 255; // prevent wrap-aroundleds[i].r = newRed;

This kind of add-and-then-check-and-then-adjust-if-needed logic is taken care of for you inside the library code for adding two CRGB colors, inside operator+ and operator+=. Furthermore, much of this logic is implemented directly in assembly language and is substantially smaller and faster than the corresponding C/C++ code. The net result is that you no longer have to do all the checking yourself, and your program runs faster, too.
这种添加然后检查然后根据需要调整的逻辑在库代码中为您处理,用于添加两种 CRGB 颜色,即 operator+ 和 operator+=。此外,这种逻辑的大部分是直接用汇编语言实现的,并且比相应的 C/C++ 代码要小得多,速度也快得多。最终结果是,您不再需要自己进行所有检查,并且您的程序运行速度也更快。

These ‘color math’ operations are part of what makes the library fast: it lets you develop your code faster, as well as executing it faster.
这些“颜色数学”操作是使库快速的部分原因:它可以让您更快地开发代码,并更快地执行代码。

All of the math operations defined on the CRGB colors are automatically protected from wrap-around, overflow, and underflow.
在 CRGB 颜色上定义的所有数学运算都会自动受到保护,防止环绕、溢出和下溢。

Adding and Subtracting Colors 添加和减去颜色

  // Add one CRGB color to another.leds[i] += CRGB( 20, 0, 0);// Add a constant amount of brightness to all three (RGB) channels.leds[i].addToRGB(20);// Add a constant "1" to the brightness of all three (RGB) channels.leds[i]++;// Subtract one color from another.leds[i] -= CRGB( 20, 0, 0);// Subtract a contsant amount of brightness from all three (RGB) channels.leds[i].subtractFromRGB(20);// Subtract a constant "1" from the brightness of all three (RGB) channels.leds[i]--;

Dimming and Brightening Colors 调光和增亮颜色

There are two different methods for dimming a color: “video” style and “raw math” style. Video style is the default, and is explicitly designed to never accidentally dim any of the RGB channels down from a lit LED (no matter how dim) to an UNlit LED – because that often comes out looking wrong at low brightness levels. The “raw math” style will eventually fade to black.
有两种不同的颜色调暗方法:“视频”样式和“原始数学”样式。视频风格是默认的,并且被明确设计为永远不会意外地将任何RGB通道从亮起的LED(无论多么昏暗)调暗到未点亮的LED,因为在低亮度水平下通常看起来是错误的。“原始数学”风格最终会褪色为黑色。

Colors are always dimmed down by a fraction. The dimming fraction is expressed in 256ths, so if you wanted to dim a color down by 25% of its current brightness, you first have to express that in 256ths. In this case, 25% = 64/256.
颜色总是变暗一小部分。调光分数以 256 度表示,因此,如果您想将颜色调暗 25% 的当前亮度,您首先必须以 256 度表示。在这种情况下,25% = 64/256。

  // Dim a color by 25% (64/256ths)// using "video" scaling, meaning: never fading to full blackleds[i].fadeLightBy( 64 );

You can also express this the other way: that you want to dim the pixel to 75% of its current brightness. 75% = 192/256. There are two ways to write this, both of which will do the same thing. The first uses the %= operator; the rationale here is that you’re setting the new color to “a percentage” of its previous value:
您也可以用另一种方式表达:您希望将像素调暗到其当前亮度的 75%。75% = 192/256。有两种方法可以写这个,这两种方法都会做同样的事情。第一个使用 %= 运算符;这里的基本原理是,您将新颜色设置为其先前值的“百分比”:

  // Reduce color to 75% (192/256ths) of its previous value// using "video" scaling, meaning: never fading to full blackleds[i] %= 192;

The other way is to call the underlying scaling function directly. Note the “video” suffix.
另一种方法是直接调用底层缩放函数。请注意“video”后缀。

  // Reduce color to 75% (192/256ths) of its previous value// using "video" scaling, meaning: never fading to full blackleds[i].nscale8_video( 192);

If you want the color to eventually fade all the way to black, use one of these functions:
如果您希望颜色最终完全褪色为黑色,请使用以下功能之一:

  // Dim a color by 25% (64/256ths)// eventually fading to full blackleds[i].fadeToBlackBy( 64 );// Reduce color to 75% (192/256ths) of its previous value// eventually fading to full blackleds[i].nscale8( 192);

A function is also provided to boost a given color to maximum brightness while keeping the same hue:
还提供了一个功能,可以在保持相同色调的同时将给定颜色提升到最大亮度:

  // Adjust brightness to maximum possible while keeping the same hue.leds[i].maximizeBrightness();

Finally, colors can also be scaled up or down using multiplication and division.
最后,还可以使用乘法和除法放大或缩小颜色。

  // Divide each channel by a single valueleds[i] /= 2;// Multiply each channel by a single valueleds[i] *= 2;

Constraining Colors Within Limits 将颜色限制在限制范围内

The library provides a function that lets you ‘clamp’ each of the RGB channels to be within given minimums and maximums. You can force all of the color channels to be at least a given value, or at most a given value. These can then be combined to limit both minimum and maximum.
该库提供了一个功能,可让您“钳制”每个 RGB 通道以在给定的最小值和最大值范围内。您可以强制所有颜色通道至少为给定值,或最多为给定值。然后可以将这些组合起来以限制最小值和最大值。

  // Bring each channel up to at least a minimum value.  If any channel's// value is lower than the given minimum for that channel, it is// raised to the given minimum.  The minimum can be specified separately// for each channel (as a CRGB), or as a single value.leds[i] |= CRGB( 32, 48, 64);leds[i] |= 96;// Clamp each channel down to a maximum value.  If any channel's// value is higher than the given maximum for that channel, it is// reduced to the given maximum.  The minimum can be specified separately// for each channel (as a CRGB), or as a single value.leds[i] &= CRGB( 192, 128, 192);leds[i] &= 160;

Misc Color Functions 其他颜色函数

The library provides a function that ‘inverts’ each RGB channel. Performing this operation twice results in the same color you started with.
该库提供了一个“反转”每个RGB通道的功能。执行此操作两次后,将生成与开始时相同的颜色。

  // Invert each channelleds[i] = -leds[i];

The library also provides functions for looking up the apparent (or mathematical) brightness of a color.
该库还提供用于查找颜色的表观(或数学)亮度的函数。

  // Get brightness, or luma (brightness, adjusted for eye's sensitivity to// different light colors.   See http://en.wikipedia.org/wiki/Luma_(video) )uint8_t luma = leds[i].getLuma();uint8_t avgLight = leds[i].getAverageLight();

Predefined colors list 预定义颜色列表

Please note - these predefined colors are defined using the W3C RGB definitions. These definitions are designed with RGB monitors in mind, not RGB leds, and so the colors that you get on LED strips may be a bit different than you’re expecting. In our experience, the colors are often too pale, or washed out (overly-desaturated).
请注意 - 这些预定义的颜色是使用 W3C RGB 定义定义的。这些定义在设计时考虑了 RGB 显示器,而不是 RGB LED,因此您在 LED 灯条上获得的颜色可能与您预期的略有不同。根据我们的经验,颜色通常太浅,或者褪色(过度饱和)。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/851613.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

我们离成功有多远呢?只要能完成自己阶段性的目标就算是一次成功

做起一个账号&#xff0c;带好一个团队&#xff0c;经营好一家公司&#xff0c;似乎这些都能叫成功&#xff0c;成功的定义可大可小&#xff0c;而我认为只要能完成自己阶段性的目标就算是一次成功&#xff0c;毕竟每个人学历、背景、阅历、资源、认知都不同&#xff0c;很难同…

重磅!最新JCR分区、中科院分区、影响因子大汇总!

【欧亚科睿学术】 期 刊 影响因子及JCR分区 2023年JCR 2023年6月&#xff0c;科睿唯安(Clarivate Analytics)发布了最新年度期刊引证报告(JCR)。 JCR 变化盘点 ① ESCI和AHCI期刊首次获得影响因子。 据最新数据显示(截止至2023年6月28日)&#xff0c;目前共有SCIE期刊95…

在AWS上运行的EKS Elastic Kubernetes Service 创建集群Cluster,Node group, Nodes

1. 前提条件 AWS Account: https://aws.amazon.com/free/Installing KubeCtl CLI https://docs.aws.amazon.com/eks/latest/userguide/getting-started-eksctl.htmlEKS Cluster RoleIAM Role for Node GroupVPCEC2 Key Pair which can be used to SSH to the worker nodesAWS …

【ppyoloe+】19届智能车完全模型组非官方基线

基于十九届智能车百度完全模型组线上赛baseline修改 调整参数最高能到0.989吧 一、环境准备 1.安装PaddleDetection In [1] # 解压PaddleDetection压缩包 %cd /home/aistudio/data/data267567 !unzip -q PaddleDetection-release-2.6.zip -d /home/aistudio /home/aistud…

【教程】从0开始搭建大语言模型:实现Attention机制

从0开始搭建大语言模型 从0开始搭建大语言模型&#xff1a;实现Attention机制建模长序列存在的问题使用attention机制获得数据间的依赖Self-attention介绍带有可训练权重的self-attention1.生成Q&#xff0c;K&#xff0c;V变量2.计算attention score3.attention weight的获得4…

支付交易——在线支付系统基本概念

摘要 本文聚集于实战&#xff0c;只讲解最实用的知识点&#xff0c;至于支付起源、在线支付发展历程等科普知识&#xff0c;感兴趣的读者可参考其它优秀的支付类书籍或网络上其它优秀的文章。本章内容对大部分专业概念进行了极致简化&#xff0c;以便更好地帮助读者入门。实际…

鸿蒙轻内核M核源码分析系列二十 Newlib C

LiteOS-M内核LibC实现有2种&#xff0c;可以根据需求进行二选一&#xff0c;分别是musl libC和newlibc。本文先学习下Newlib C的实现代码。文中所涉及的源码&#xff0c;均可以在开源站点https://gitee.com/openharmony/kernel_liteos_m 获取。 使用Musl C库的时候&#xff0c…

具有可编程电流限制的1.5A电源开关LPW5210用于5V或USB供电输出过流保护只要3毛

前言 适合要求反应时间较快的保护电路&#xff0c;保险丝或自恢复保险丝也能起到保护作用&#xff0c;但断开电流是额定电流的一倍&#xff0c;过流较小时&#xff0c;甚至需要数秒或更长的时间才能保护&#xff0c;因此半导体的过流保护开关更合适&#xff0c;相对成本要高一…

replaceAll is not a function 详解

先说说原因&#xff1a; 在chrome 浏览器中使用 replaceAll 报这个错误&#xff0c;是因为chrome 版本过低&#xff0c; 在chrome 85 以上版本才支持 用法 replaceAll(pattern, replacement)const paragraph "I think Ruths dog is cuter than your dog!"; console…

数据可视化后起之秀——pyecharts

题目一&#xff1a;绘制折线图&#xff0c;展示商家A与商家B各类饮品的销售额 题目描述&#xff1a; 编写程序。根据第9.3.1&#xff0c;绘制折线图&#xff0c;展示商家A与商家B各类饮品的销售额。 运行代码&#xff1a; #绘制折线图&#xff0c;展示商家A与商家B各类饮品的…

淘宝数据抓取的全景解析

——分析淘宝数据抓取的常见方法及其适用场景&#xff0c;探讨不同技术如何影响数据的质量和可用性 在当今数据驱动的电子商务时代&#xff0c;能够有效地抓取和利用数据成为商家获得竞争优势的关键。淘宝作为中国最大的在线零售平台&#xff0c;其海量数据具有极高的价值&…

Spring--Bean的作用域,生命周期

Bean的作用域 Bean的作用域有很多种&#xff0c;在Spring Framework中支持6种&#xff08;其中有四种只有在web环境中才能生效&#xff09;&#xff0c;同时Spring还支持自定义Bean的范围。 Spring Framework中支持的6种范围&#xff1a; 作用域解释singleton每个Spring IoC…

从零到一建设数据中台(番外篇)- 数据中台UI欣赏

番外篇 - 数据中台 UI 欣赏 话不多说,直接上图。

想让谷歌独立站关键词排名一飞冲天?这个秘密技巧必须知道!

在激烈的谷歌排名竞争中&#xff0c;我们要确保自己优化的独立站在谷歌搜索结果中占据首页位置至关重要。排名首页不仅能显著提高展现和流量&#xff0c;还能带来更多潜在客户和业务机会。本文将从谷歌SEO技术的角度&#xff0c;深入探讨在谷歌独立站关键词排名首页最重要的几个…

ShardingSphere跨表查询报错

目录 一、场景简介二、报错信息三、SQL四、原因五、解决方法一、调整SQL&#xff0c;不使用子查询方法二、将子查询的SQL独立出来&#xff0c;后续连接逻辑由代码处理 一、场景简介 1、使用ShardingSphere按月份进行分表 2、单月查询正常&#xff08;单表&#xff09; 3、跨…

CA证书及PKI

文章目录 概述非对称加密User Case: 数据加密User Case: 签名验证潜在问题 CACA证书的组成CA签发证书流程CA验证签名流程CA吊销证书流程 PKI信任链证书链 概述 首先我们需要简单对证书有一个基本的概念&#xff0c;以几个问题进入了解 ❓ Question1: 什么是证书&#xff1f; 证…

福利|免费申请长期单域名、通配符、多域名SSL证书,不限量

一、什么是单域名、通配符、多域名SSL证书 单域名证书&#xff1a;仅保护一个特定的域名。 通配符证书&#xff1a;保护一个主域名及其所有二级子域名。 多域名证书&#xff1a;在同一张证书中保护多个不同的域名&#xff0c;可以是主域名也可以是子域名&#xff0c;域名之间…

目前比较好用的LabVIEW架构及其选择

LabVIEW提供了多种架构供开发者选择&#xff0c;以满足不同类型项目的需求。选择合适的架构不仅可以提高开发效率&#xff0c;还能确保项目的稳定性和可维护性。本文将介绍几种常用的LabVIEW架构&#xff0c;并根据不同项目需求和个人习惯提供选择建议。 常用LabVIEW架构 1. …

Invalid keystore format,获取安全码SHA1值出错

AndroidStudio版本&#xff1a;Android Studio Electric Eel | 2022.1.1 项目运行JDK版本&#xff1a;11.0.15&#xff0c;查看方法如下&#xff1a; 在Terminal 窗口中&#xff0c;获取的Java版本是&#xff1a;1.8.0&#xff0c;修改Java系统环境变量&#xff0c;改成&#…

如何在MySQL中创建不同的索引和用途?

目录 1 基本的 CREATE INDEX 语法 2 创建单列索引 3 创建多列索引 4 创建唯一索引 5 创建全文索引 6 在表创建时添加索引 7 使用 ALTER TABLE 添加索引 8 删除索引 9 索引管理的最佳实践 10 示例 在 MySQL 中&#xff0c;索引&#xff08;index&#xff09;是一种用于…