Single Color Snake Pattern?

Hello! I’m trying to create a single color snake pattern and I’m having some issues. I’m very new with all of this so I would appreciate any help or pointers.

I started with this rainbow snake pattern that works perfectly:

distance = 50

export function beforeRender(delta) {
  t1 = time(.17)
}

export function render(index) {
  h = index/pixelCount
  s = 1
  v = 1
  
  head = t1 * 112
  offset = (head - index + 112) % 112
  
  hsv(h, s, clamp(1 - offset / distance, 0, 1))
}

Then I modified it to run a white snake pattern:

distance = 50

export function beforeRender(delta) {
  t1 = time(.17)
}

export function render(index) {
  h = 0
  s = 0
  v = 1
  
  head = t1 * 112
  offset = (head - index + 112) % 112
  
  hsv(h, s, clamp(1 - offset / distance, 0, 1))
}

I would now like to run the exact same pattern as the white snake, but with solid colors. However I can’t seem to get it to work. If I change the “s” value to anything other than 0 the color turns to green and I can’t get it to produce any other colors. Is there a straight forward way of doing this which would allow me to choose a few different solid colors to run with this pattern?

H S V stands for Hue (color, basically), Saturation (how gray / desaturated the color is) and Value (basically brightness).

You want to control the COLOR with H, not S.

If you scroll down on Getting Started with PixelBlaze — Ben Hencke to “Writing Your First Pattern” it’s decently well explained.

Thanks for the reply! I’ve tried that as well, but no mater what value I give it it remains white.

That’s because you have s = 0 which means 0 saturation. :relaxed:

2 Likes

That makes sense, however I’m still confused why if I make S anything above 0 why it will only run a single green color. The strip I’m using is these 12v RGBW pixels: https://www.enttec.com/product/led-pixel-strip/black-led-pixel-strip/. Does it have something to do with it being RGBW instead of RGB? The rest of the effect works exactly how I want, but I just need to be able to choose the color and as of right now it will only do all white or one specific shade of green.

You first need to make sure that you’ve selected the right type of LED strip and color order in settings. (If you’re not sure, play around with different options while running a simple test pattern). RGBW strips work fine, but the color order may or may not be that order on your actual strips.

Then, control the color (hue) with H, and just set the saturation to 1.

1 Like

I set the color order according to the LEDs spec sheet and all the test patterns are running correctly. Still though, whenever I set the saturation to anything above 0 with any hue setting it will only show green.

Can you share the code snippet you’re working on now that you have implemented the notes above from me and @sorceror , as well as a screenshot of your settings screen where you picked the LED type? (I also might be missing something obvious; also don’t assume the LED spec sheets are correct necessarily).

Hue = 0 Saturation = 1 Value = 1 should be red, not green… I had this bookmarked from walking though a similar problem in the past. Working with Hues in Pixelblaze - color ranges, blending

Of course, thank you so much for the help! Here is the code I’m using… I just updated it to Hue = 0 Saturation = 1 Value = 1 and its still running all the lights as green. I thought they might be broken, but that doesn’t seem to be the case since they have zero problem running the rainbow pattern which shows all the colors.

Here is my code:

distance = 50

export function beforeRender(delta) {
  t1 = time(.17)
}

export function render(index) {
  h = 0
  s = 1
  v = 1
  
  head = t1 * 112
  offset = (head - index + 112) % 112
  
  hsv(h, s, clamp(1 - offset / distance, 0, 1))
}

Here is a screenshot of my settings:

If you run the pre-loaded pattern called KITT, does the pattern show as green or red? If green, then the problem is the Color Order in Settings is wrong. If Red, I’m really confused. Alternatively, if you set H to 0.5 or 0.25, what color do you get? Still green or a different color?

For quick reference when testing, if the color order is correct and everything else is working properly then:

  • hsv(0,1,1) is red
  • hsv(0.33333,1,1) is green
  • hsv(0.6666,1,1) is blue

Another thing you might want to do is set the brightness limit for your LEDs to 50% or less until you’ve got it working correctly, to be sure that the power supply can keep up as you test.

2 Likes

You said they are RGBW strips but your screenshot shows Color Order GRBW which would explain why Hue 0 gives you Green. As @ZacharyRD says … the KITT pattern should be red. Is it?

Ah! Ok Now I’m getting somewhere! I set it to RGBW and now its operating as you just described @zranger1 and @sorceror. I’m able to get red, green and blue independently by using:

  • hsv(0,1,1) is red
  • hsv(0.33333,1,1) is green
  • hsv(0.6666,1,1) is blue

So then my next question is if there is a way to use the outputs from a HEX/RGB to HSV calculator to figure out my HSV values. I used a calculator to try to get the correct color but the Hue output is way outside of the range that works with the pixel blaze. Here is a screenshot to show what I mean:

If I set the Hue to 171 it outputs as red, which makes sense since it is >1. Is there a way to get a corresponding hue value that works with the Pixelblaze?

1 Like

Quick answer: The Pixelblaze uses normalized values in the range [0.0,1.0] for just about everything. It makes a whole lot of math a whole lot easier in the long run. Plus it lets Pixelblaze patterns run on LEDs with >8-bit color depth without changing any code.

To convert from a 360 degrees/100%/100% based HSV color, just divide hue by 360,and saturation and value by 100.

For the color above, that’ll give you (0.475, 0.9, 0.196)

(This applies to RGB colors as well – red is rgb(1,0,0), green rgb(0,1,0), and so forth. To convert from [0,255]-based colors, divide by 255.)

1 Like

Ok Great! Thanks so much this is perfect. I really appreciate all of your help. Everything’s now working as intended!

4 Likes