简体   繁体   English

#Define,NeoPIxel的RGB颜色

[英]#Define , RGB colors for NeoPIxel

Am playing with the NeoPixels on the Particle Photon. 我正在使用粒子光子上的NeoPixels。 Have got example code up an running which spins the neopixels through different colors. 有示例代码运行,使新像素旋转通过不同的颜色。 However a little confused on how to extend this, particularly with the way it has defined the neopixel colors. 但是,对于如何扩展它,尤其是它定义新像素颜色的方式,有些困惑。

The sketch defines the colors as so 草图将颜色定义为

#define BLUE 5,5,190
#define WHITE 150,150,150
#define GREEN 10,180,10

and calls the following function Spin in this fashion 并以这种方式调用以下函数Spin

spin (BLUE);

void spin(int R, int G, int B) {
     for(i=0; i < PIXEL_COUNT; i++) {
         strip.setPixelColor(i, R,G,B);
         strip.show();
         delay(waitTime);
     }
     for(i=0; i < PIXEL_COUNT; i++) {
         strip.setPixelColor(i, 0,0,0);
         strip.show();
         delay(waitTime);
     }
 }

I want to send the Photon commands to change the color, so need to set a variable equal to one of the defined colors and pass to the spin function. 我想发送Photon命令来更改颜色,因此需要设置一个变量,使其等于定义的颜色之一,并传递给spin函数。 However, setting the variable to Int fails ie 但是,将变量设置为Int失败,即

int lightcolor = BLUE;

I have also tried an array 我也试过一个数组

int lightcolor [] = BLUE;

this fails as well. 这也失败了。

i managed to get int lightcolor [1,1,1] = BLUE 我设法得到int lightcolor [1,1,1] = BLUE

to pass the compiler, but it failed on the functional call 传递编译器,但在功能调用上失败

spin(lightcolor) 旋(lightcolor)

or spin(lightcolor[1,1,1]} 或spin(lightcolor [1,1,1]}

just not sure what I am missing here with regard to how the #define declares that const and how to use it throughout the sketch 只是不确定我在这里关于#define如何声明该const以及如何在整个草图中使用它而丢失了什么

thanks 谢谢

You should look up what a define statement actually is. 您应该查询一下define语句实际上是什么。 The preprocessor will replace BLUE with the characters 5,5,190 in the source file before the compiler even sees it. 在编译器尚未看到之前,预处理器将在源文件中用字符5,5,190替换BLUE。

Thus, spin(BLUE) works because spin(5,5,190) works. 因此,spin(BLUE)有效,因为spin(5,5,190)有效。 If you want to assign BLUE to a variable, you actually have to assign it to three variables because spin takes three independent variables, one for each color channel. 如果要将BLUE分配给变量,则实际上必须将其分配给三个变量,因为spin需要三个独立变量,每个颜色通道一个。 Why even assign to a variable anyway? 为什么还要分配一个变量呢? Why not use the define? 为什么不使用定义?

Read an intro to c or c++ (they're different languages) and learn what you're doing. 阅读c或c ++的介绍(它们是不同的语言),并了解您的工作。 Poking around blindly like you're doing is unlikely to produce good results. 像您一样盲目四处张望,不太可能产生良好的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM