Dear coders, i am looking for some help.
I tried to create a slider as a ‘runner-up’. (no leds when 0, all pixels on when 1)
But i kept on getting errors of all kind.
Someone has done this before?
The plan is to later replace the slider by an analog input from a potmeter.
Thanks
Hi,
If I understand correctly, you want to use a slider, and eventually a potentiometer to control how many of the LEDs are lit on a strip or other display. Here’s one way you might do that, based on the default “rainbow” pattern (the pattern you get when you press the “New Pattern” button.)
// start with all LEDs lit
var onPct = 1
export function sliderLightsOn(v) {
onPct = v
}
export function beforeRender(delta) {
t1 = time(.1)
}
export function render(index) {
// calculate the position of the current LED as a percentage of the
// total. We'll use this to generate the rainbow color, and to
// determine which LEDs should be turned on.
pct = index/pixelCount;
// animated rainbow hue
h = t1 + pct
// LED will be lit if the current slider setting is greater than
// the LED's % position in the strip. Move the slider to change
// the number of lit LEDs.
hsv(h, 1, onPct > pct)
}
2 Likes
Thanks a lot Zranger, works perfectly with great potential. I am building a tubular lamp that you can dim by rotating it. Now i can add a ‘linear’ dim. I will send video soon.
1 Like