Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added user-friendly support for commonly used colors #166

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

patrick9958
Copy link

I've assembled a list of 140 preset colors so that instead of typing, for example, theaterChase(strip.Color(20,34,16), delayval), users can type theaterChase(TEAL, delayval). Both options for typing colors are available to users and the function will work either way. I've also put all 140 colors into the keywords.txt file and marked them as KEYWORD2 so users know it will be recognized as a valid color by Arduino. I've already written code and tested it on two separate LED ring models.

I have changed the Adafruit_Neopixel.h file only by adding the #include "hexadecimal_colors_to_strings.h" at the top. I have added a new hexadecimal_colors_to_strings.h file in the directory as well. This file defines a list of 140 commonly used colors along with their hex values.

On top of that, I added a new example file called colors.ino in which I demonstrate how these colors can be used.

Patrick Neggie added 4 commits May 29, 2018 13:53
no additional functions were added to the library. the preset colors you can find in hexadecimal_colors_to_strings.h are now usable in the setPixelColor() function. colors are also color-coded in KEYWORD2 for enhanced user experience. example can be found in colors.ino in examples folder
@ladyada
Copy link
Member

ladyada commented May 29, 2018

great start! can you remove all changes to NeoPixel.cpp and .h? you dont need to include the colors header file there and cpp has some white space changes (which i'd like to not have in this PR!)

deleted all whitespace modifications and .cpp file now matches the one in the original adafruit neopixel library
@patrick9958
Copy link
Author

patrick9958 commented Jun 28, 2018

First of all, sorry for taking so long to get back to you. Secondly, I removed all changes to the Neopixel.h and .cpp files. However, when you remove the include reference to the hexadecimal_colors_to_strings.h in the .h file, colors.ino does not compile (reflected by the failed build) because TEAL, YELLOW, and MAROON are now not declared. I could put the library include for the hexadecimal_colors_to_strings.h file at the top of the example but that would kind of defeat the purpose of integrating it within the Adafruit Neopixel library. Let me know how you want me to move forward.

@lights0123
Copy link

I'd like to see these constants namespaced, either by prefixing them with NEO_ or doing something like this:

namespace NeoColors {
  const uint32_t BLACK = 0x000000
  const uint32_t NAVY = 0x000080
}

Because otherwise any user sketches with any of these names won't work anymore. I've seen a couple of LCD graphics libraries that have these same constants, and those sketches won't work anymore without modifying either library (or adding hundreds of #undefs). This also allows sketches to just add using namespace NeoColors; if they aren't using anything that has a conflict to just use the short name.

@patrick9958
Copy link
Author

I have the #include <stdint.h> at the top of the hexadecimal_colors_to_strings.h file because Arduino was not recognizing uint32_t as a type but the example colors.ino file still won't compile because the hexadecimals.h file isn't included anywhere

@ladyada
Copy link
Member

ladyada commented Jan 26, 2019

please ping when this compiles and passes travis CI

@abhinuvpitale
Copy link

You need to include "hexadecimal_to_string.h" header

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants