Use RGB color scheme for first pixel in blade?

Hello there,

A week or two ago, I accidentally broke the pixel that illuminated the Kyber crystal in my Starkiller lightsaber. I am using this as an opportunity to wire in a new Kyber crystal that looks more natural. Unfortunately, the LED I wired in seems to use the RGB color scheme as opposed to GRB. This saber is quite difficult to work on, so I’m hoping to use a software solution as opposed to a hardware solution to fix this. The crystal LED is a single neopixel LED wired in parallel with the blade. I’m hoping that I can pull some programming magic to make the first pixel of the blade use the RGB color scheme while all the other pixels use GRB. The one pixel of the blade that would be the wrong color would be hidden by the emitter, so it should turn out alright. Does anyone know if there’s a way to do this without having to rewire this single pixel to a different data line? Perhaps without having to recode all the blade styles to have the first pixel a different color?

“Simplest” would be a SubBlade for that 1 pixel and then set the color in styles for the 1 pixel “Blade” to account for the difference.

It might take some trial and error but you could either choose styles with the color adjusted, like picking Blue instead of Green -or- “rotate” the colors by wrapping RotateColorsX<> around the style and determining the rotation needed.


StylePtr<main blade>(),
StylePtr<RotateColorsX<Int<10992>,main blade>>()


StylePtr<main blade>(),
StylePtr<RotateColorsX<Int<21844>,main blade>>()

Depending on RGB order.

Thank you! I’ll see if I can figure that out.

No matter what I do, I can’t seem to get it to compile with a sub blade. Here’s the Blades section I have right now:

BladeConfig blades[] = {
  { 0,
	SubBlade(1, 144, WS281XBladePtr<145, bladePin, Color8::GRB, PowerPINS<bladePowerPin2, bladePowerPin3, bladePowerPin5>>()),
	SubBlade(0, 0, NULL),

It throws several errors when I try to compile it:

error: cannot convert 'BladeBase*' to 'Preset*' in initialization
  293 |  SubBlade(0, 0, NULL),
      |  ~~~~~~~~^~~~~~~~~~~~
      |          |
      |          BladeBase*

error: invalid conversion from 'Preset*' to 'size_t' {aka 'unsigned int'} [-fpermissive]
  294 |  CONFIGARRAY(presets),
      |              ^~~~~~~
      |              |
      |              Preset*

note: in definition of macro 'CONFIGARRAY'
    6 | #define CONFIGARRAY(X) X, NELEM(X)
      |                        ^

error: invalid conversion from 'unsigned int' to 'const char*' [-fpermissive]
  299 | #define NELEM(X) (sizeof(X)/sizeof((X)[0]))
      |                  ~~~~~~~~~~^~~~~~~~~~~~~~~~
      |                            |
      |                            unsigned int

note: in expansion of macro 'NELEM'
    6 | #define CONFIGARRAY(X) X, NELEM(X)
      |                           ^~~~~

note: in expansion of macro 'CONFIGARRAY'
  294 |  CONFIGARRAY(presets),
      |  ^~~~~~~~~~~
exit status 1
invalid conversion from 'unsigned int' to 'const char*' [-fpermissive]

Do you have any idea what I’m doing wrong?

Did you set NUM_BLADES at top to 2?
Do you have 2 styles in each preset?
Otherwise need to post your config.

Instead of using RotateColors, I suggest using ByteOrder<> instead, like:

StylePtr<main blade>(),
StylePtr<ByteOrder<Color8::RGB, main blade>>(),

Byteorder is designed for this purpose, it’s both faster and more capable. (RotateColors can’t do all byte-order transformations correctly.)

1 Like

I didn’t know about ByteOrder. Thanks, learn something new every day :grinning:

1 Like

I did not set the blade number to 2. Let me try that

Alright, setting the blade number to 2 did solve the compilation problems. Now I can’t seem to figure out how to incorporate ByteOrder into the config. I’m going to post one of the blade profiles and how I tried to implement it, and I’d appreciate it if someone would correct where I messed up.

{ "Bank33;common",  "tracks/mars.wav",

StylePtr<ByteOrder<Color8::RGB, main blade>>()},

I’m getting these errors:

Arduino: 1.8.13 (Windows 10), Board: "Proffieboard V2, Serial, SDCARD (SPI), 80 MHz, Smallest Code"

In file included from C:\Users\o\OneDrive\Documents\ProffieOS-v6.7\ProffieOS\ProffieOS.ino:563:

sketch\config/StarkillerTXQ.h:185:10: error: 'ByteOrder' was not declared in this scope; did you mean 'BitOrder'?

  185 | StylePtr<ByteOrder<Color8::RGB, main blade>>(),

      |          ^~~~~~~~~

      |          BitOrder

sketch\config/StarkillerTXQ.h:185:33: error: 'main' was not declared in this scope; did you mean 'min'?

  185 | StylePtr<ByteOrder<Color8::RGB, main blade>>(),

      |                                 ^~~~

      |                                 min

sketch\config/StarkillerTXQ.h:185:1: error: parse error in template argument list

  185 | StylePtr<ByteOrder<Color8::RGB, main blade>>(),

      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

sketch\config/StarkillerTXQ.h:185:46: error: no matching function for call to 'StylePtr<<expression error>, <expression error> >()'

  185 | StylePtr<ByteOrder<Color8::RGB, main blade>>(),

      |                                              ^

In file included from sketch\styles/fire.h:4,

                 from C:\Users\o\OneDrive\Documents\ProffieOS-v6.7\ProffieOS\ProffieOS.ino:426:

sketch\styles/style_ptr.h:93:16: note: candidate: 'template<class STYLE> StyleFactory* StylePtr()'

   93 | StyleAllocator StylePtr() {

      |                ^~~~~~~~

sketch\styles/style_ptr.h:93:16: note:   template argument deduction/substitution failed:

In file included from C:\Users\o\OneDrive\Documents\ProffieOS-v6.7\ProffieOS\ProffieOS.ino:563:

sketch\config/StarkillerTXQ.h:185:46: error: wrong number of template arguments (2, should be 1)

  185 | StylePtr<ByteOrder<Color8::RGB, main blade>>(),

      |                                              ^

exit status 1

Error compiling for board Proffieboard V2.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I’m afraid I’m a bit out of my depth here.

Where I wrote “main blade” that is meant to be the style code from your main blade just copy the code from first style inside StylePtr<…>() in place of "main blade. ByteOrder is meant to be wrapped around the style code of your main blade code to adjust it :wink:

Ops, it’s not ByteOrder<> it’s actually ByteOrderStyle<>, so:

And just like Fett263 said “main blade” is just a placeholder for your actual blade style.

Alright. So how would I get it to effect only the first pixel of the blade?

SubBlade does that.

Indeed! Holy cow.