Hi everyone. I need some assistance with some code.

Hi everyone. I need some assistance with some code.
I have a single ws2812 and I am using HSV to control it. I want to vary the value in the HSV by a random amount at a random time and have it fade nicely between given values. I have cobbled together some code that does this but not nicely. I am using the random number generator in arduino and it sucks frankly. I would like to use the noise8 function but not sure how to do so. everything I’ve read online is using noise8 in a dimensional array, not for generating single dimension values. any help would be appreciated. I can post the code I currently use if it helps.

To fade between given values, I’d be using blend().

As for noise, I typically only use it in 1D applications. For instance:

Oh, and I prefer to use palettes as opposed to direct HSV assignment. Allows for a LOT more flexibility, because you can change palettes on the fly as shown in the above example.

Edit: Here’s a blend demo:

ok, My issue would be that the light is only displaying one color not a palette. it has to remain blue, but flicker like a candle between a given minimum value and maximum value. where value is the brightness of the HSV values. Hue and saturation is untouched in this program.

If you want it to flicker like a candle (with the top being darker), I’d get a copy of:

and change the palette. I did a version where you change the HSV and the candle changes colour.

If you just want to flicker and not worry about the actual ‘candle’ effect, I’d use the noise routine above and create a palette of similar colours and varying brightnesses.

For instance:

targetPalette = CRGBPalette16( CHSV(palhue, 255, 0), CHSV(palhue, 255, 160), CHSV(palhue, 255, 224), CHSV(palhue, 255, 255));

I’ll look in to it, I’d have to modify it to work on a single pixel with only one color. lol

Well, there’s lots of examples above, and several ways to do it. Have fun.

The other recommendation I have is to try not use delay() statements. They cause havoc if you ever want to add pushbuttons or other controls down the road.

This turns out to be a bit tricky, but for a single pixel, I have a candle class that I think flickers very nicely, just using random(). Sorry, code isn’t well commented, but it’s pretty simple. Just grab the class TikiCandle and call the init() function with the HSV color you want, a value lower and higher to allow the color to vary a bit. The last three parameters control how likely the hue or variance are to change with each iteration. The last param, hue priority, specifically tells the system how likely a change in color should be over time. This means if you pick yellow to be a candle, it might be a bit more red or orange over time to allow for a bit of a soft color effect.

Then call run() for a single pixel change (potentially, random() does a good job of not actually causing wide ranging changes with this setup). Adding delay can slow down the flicker, but requires some playing around. This repo is for a Photon, which introduces enough delay for each iteration to make it look good without actually calling delay. Ironically enough, I have a small delay on slower chips without WiFi and whatnot because the loop() goes fast enough.

It’s not perfect, but I use it to mimic candle flicker in small printed jack o’lanterns and in some tiki torches I built that sit in my backyard. I think it’s nice, my wife likes it. I can’t say it’s perfect, but it’s simple and works pretty well. I can comment it up a bit and split out the candle effect into it’s own repository if requested which is something I have thought about doing a bit anyway.

https://github.com/buelowp/tikitorch

I’m well aware thanks. I already have two state machines and a function button in this project as well as a menu system to select brightness and hue and store it in eeprom. I just need a simple way of making the V in HSV vary in a random pattern that resembles a candle. nothing fancy or complicated. The method I have is literally just taking a random number mapped between a min and max setting and fading between it and the last value at a randomized interval. it works but its not realistic at all.

@Peter_Buelow Thank you, I will have a look at it and see if I can do something similar.

@Andrew_Tuline I have modified my whole program to switch everything over to using CHSV. I then used blend to smoothly transition between the normal mode which is blue and the call mode which is green. it looks great and allows me to add in the ability to change the hue for both functions in settings and maintain a nice transition regardless of hues chosen by the user. that worked great. But I still want to incorporate some way to make it looke more like a real candle flame flickering with just the one hue, the user doesn’t want the hue to change. I’m still trying to figure out how to use fast leds built in functions to my advantage for this in a single led array with no dimensions. Thank you for your suggestions though!