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.

Like

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

or

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),
	CONFIGARRAY(presets),
  }
};

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<Layers<StyleFire<Strobe<RotateColorsX<Variation,Rgb<95,0,210>>,Strobe<Rgb<100,100,150>,RandomPerLEDFlicker<RotateColorsX<Variation,Rgb<95,0,210>>,Black>,50,1>,100,1>,RotateColorsX<Variation,Rgb<23,0,65>>,0,5,FireConfig<2,1000,5>,FireConfig<2,1000,5>,FireConfig<2,1000,5>,FireConfig<2,1000,5>>,
  TransitionEffectL<TrConcat<TrFade<400>,AudioFlickerL<RotateColorsX<Variation,Rgb<160,60,255>>>,TrDelay<1000>,AudioFlickerL<RotateColorsX<Variation,Yellow>>,TrFade<800>>,EFFECT_FORCE>,
  AlphaL<Stripes<1000,-2000,RandomPerLEDFlicker<RotateColorsX<Variation,Rgb<95,0,210>>,Black>,White,RotateColorsX<Variation,Rgb<95,0,210>>,White>,SwingSpeed<600>>,
  LockupTrL<Layers<
  AlphaL<AudioFlickerL<HotPink>,Bump<Scale<BladeAngle<>,Scale<BladeAngle<0,16000>,Int<10000>,Int<30000>>,Int<10000>>,Scale<SwingSpeed<100>,Int<14000>,Int<18000>>>>,
  AlphaL<DeepPink,Bump<Scale<BladeAngle<>,Scale<BladeAngle<0,16000>,Int<10000>,Int<30000>>,Int<10000>>,Int<10000>>>>,TrConcat<TrInstant,White,TrFade<400>>,TrConcat<TrInstant,White,TrFade<400>>,SaberBase::LOCKUP_NORMAL>,
  ResponsiveLightningBlockL<Strobe<Blue,AudioFlicker<White,Blue>,50,1>,TrConcat<TrInstant,AlphaL<White,Bump<Int<12000>,Int<18000>>>,TrFade<200>>,TrConcat<TrInstant,HumpFlickerL<AlphaL<White,Int<16000>>,30>,TrSmoothFade<600>>>,
  AlphaL<Black,SmoothStep<Scale<SlowNoise<Int<1600>>,Int<1000>,Int<4000>>,Int<-4000>>>,
  ResponsiveStabL<Red>,
  ResponsiveBlastL<Yellow,Int<400>,Scale<SwingSpeed<200>,Int<100>,Int<400>>>,
  ResponsiveBlastWaveL<Yellow,Int<300>,Int<100>,Int<300>,Scale<BladeAngle<0,16000>,Int<10000>,Int<30000>>,Int<10000>,EFFECT_CLASH>,
  AlphaL<Black,SmoothStep<Scale<SlowNoise<Int<2400>>,Int<22000>,Int<40000>>,Int<22000>>>,
  LockupTrL<AlphaL<BrownNoiseFlickerL<White,Int<300>>,SmoothStep<Int<30000>,Int<5000>>>,TrWipeIn<400>,TrFade<300>,SaberBase::LOCKUP_DRAG>,
  LockupTrL<AlphaL<Mix<TwistAngle<>,Red,Orange>,SmoothStep<Int<28000>,Int<5000>>>,TrWipeIn<600>,TrFade<300>,SaberBase::LOCKUP_MELT>,
  InOutTrL<TrWipeSparkTip<White,300>,TrWipeInSparkTip<White,800>>,
  TransitionEffectL<TrConcat<TrFade<100>,AlphaL<HumpFlickerL<Magenta,10>,Bump<Int<0>,Int<4000>>>,TrFade<100>,AlphaL<HumpFlickerL<Magenta,15>,Bump<Int<0>,Int<5000>>>,TrFade<100>,AlphaL<HumpFlickerL<Magenta,20>,Bump<Int<0>,Int<6000>>>,TrBoing<1000,0>>,EFFECT_PREON>>>(),


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.