How to use "WS2812_Definitions.h" with Neopixel Library?

I have included at the beginning of my sketch:

#include <Adafruit_NeoPixel.h>
#include "WS2812_Definitions.h"

Will this enable me to use the color names from Definition.h in the body of my sketch such as:

leds.setPixelColor(0, DARKORANGE);

The #include "WS2812_Definitions.h" produces a compiler error. Am I misunderstanding the purpose of #include "WS2812_Definitions.h"?

DonpK:
I have included at the beginning of my sketch:

#include <Adafruit_NeoPixel.h>
#include "WS2812_Definitions.h"

Will this enable me to use the color names from Definition.h in the body of my sketch such as:

leds.setPixelColor(0, DARKORANGE);

Yes.

The #include "WS2812_Definitions.h" produces a compiler error. Am I misunderstanding the purpose of #include "WS2812_Definitions.h"?

You should have posted the compiler error, (within code tags, needless to say).

My guess is that you don't have that file in your sketch directory. It's not a part of the "Adafruit_NeoPixel" library, and must be downloaded separately and placed into the folder that holds your sketch.

To make things easier, I've attached a copy of the "WS2812_Definitions.h" file. As mentioned, just place it in your sketch folder before opening the sketch, and it will appear on a second tab in the IDE when you open the sketch.

Then, in your sketch, you can use all of those defines by name, like "DARKORANGE", "SEASHELL", "STEELBLUE" etc etc

So, for example, instead of this:-leds.setPixelColor(0, 0xFF00FF);    // Set the first LED to full red, no green, full blueyou could do this:-leds.setPixelColor(0, MAGENTA);    // Set the first LED to full red, no green, full blue

WS2812_Definitions.h (4.21 KB)

Thanks, OldSteve,

I followed up on your information and found the problem.

I have been trying an Arduino IDE called "Programino" which, for some reason, isn't loading the "Definitions.h" as a separate tab. In fact, even when I open it in a separate tab, the sketch still doesn't compile properly.

When I open my sketch with the standard Arduino IDE, it works just as you describe.

I'll have to find out what the problem is with Programino. If anyone else is interested, let me know and I'll post my findings here. I'm not sure how widely used Programino is. I like it, but it's still in development.

For what it's worth, I'll post the Programino compiler error message below:

Verify code please wait...
Last verify at: 10:52:58

Sketch uses 3,134 bytes (1%) of program storage space. Maximum is 253,952 bytes.
Global variables use 35 bytes (0%) of dynamic memory, leaving 8,157 bytes for local variables. Maximum is 8,192 bytes.

In file included from C:\Users\Office\Favorites\Electronics\Arduino\WS2812_Test\WS2812_Test.ino:3:0:

sketch\WS2812_Definitions.h:136:0: warning: "PINK" redefined [enabled by default]

#define PINK 0xFFC0CB

^

In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\iom2560.h:38:0,

from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:174,

from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:88,

from C:\Users\Office\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.10\cores\arduino/Arduino.h:28,

from sketch\WS2812_Test.ino.cpp:1:

c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\iomxx0_1.h:1132:0: note: this is the location of the previous definition

define PINK _SFR_MEM8(0x106)

^

For what it's worth, I'll post the Programino compiler error message below:

While you may think that PINK is a color name, the Arduino knows that the K port is named PINK (on those boards that have a K port).

You need to use a different name in the WS2812_Definitions.h file.

Paul,

That appears to have been the core problem. When I comment-out PINK in the Definitions file and save it, no compiler error is generated.

Unlike the standard Arduino IDE, Programino doesn't open the .h file in the IDE as a separate tab. However, it does access it as long as it's in the same folder as the sketch using it and compile okay.

"A port named PINK", boy, I don't know if I would have figured that one out. Thanks.

Hello,

i think you have used the Programino Library import function ("Copy Lib to Project-Folder" this is only a option in Programino and works fine with correct writen Libs). Arduino find in this case two same Libs, once in Arduino IDE folder and once in your Project folder. In this case delete the Lib in your project folder and Arduino use the original Lib.

I think the problem is in the Lib c or header file:

A proper Lib prevented that a library can be loaded multiple times.

#ifndef MY_HEADER
#define MY_HEADER

#endif

The file name must not be changed!