Here's a "LED Candle" project I made as a birthday present.  It uses a

Here’s a “LED Candle” project I made as a birthday present. It uses a Beetle board and an @Adafruit_Industries Neopixel ring, and of course FastLED! More details are listed in the video description.

The code that reads the right potentiometer is setup so it switches the candle into one of three different modes. When reading the pot value (0-1023), if it is less then 40 it runs in “normal candle mode”. If the pot reads 41 to 949 then that value is scaled into the range 0-255 which allows the user to dial in a specific (FastLED) hue. And if the pot reads 950+ the candle goes into “random mode” and picks between several different colorful displays/random patterns, switching every minute. The beauty of having NUM_LEDS be only 12 pixels allowed me to keep my FPS in the range of ~140 to 500+ depending on what mode it was running. I also added a call to the function that read the current pot values in several select places in the code so I could keep the knobs fairly responsive even when the FPS were on the lower end.

As the birthday day approached, of course I ran out of time coding it to what I fully wanted, but that’s what version #2 will be for, right? :slight_smile: I do feel like I improved my still basic coding skills though, and had a lot of fun learning a variety of new stuff on this project.

and a second one:

Marc, is the code for this available? Looking to learn using two pots for hue and brightness. Or if you know of any other code examples that might be helpful… Thanks

It’s not, but I will grab out that part of code and post. Might be a few days as I’m traveling now. In the mean time look at this. Ignore the servo part and think of how you could replace that to set the FastLED master brightness, or a hue.

http://arduino.cc/en/tutorial/knob
http://arduino.cc/en/Reference/Map

@Stefin_T ​, here’s another example of using potentiometers for setting values that might be useful.
https://plus.google.com/101659586657126875520/posts/668HFVvYXMF

Cleaned up post, code posted had many errors

(Looked at the link you posted)

Also, playing with the Hue part… if I use the code below, the pot will cycle through the various hues but only on led 0 not the entire strip.

What part in code defines the entire strip versus the first led?

#include <FastLED.h>

#define NUM_LEDS 30
#define DATA_PIN 6
#define CHIPSET WS2811

CRGB leds[NUM_LEDS];

//int poti1 = 0; //position
int poti2 = 1; //hue
//int poti3 = 2; //saturation

//int poti1val = 0;
int poti2val = 0;
//int poti3val = 0;

int mapLeds = 0;

uint8_t hue = 0;
uint8_t saturation = 255;

void setup() {
Serial.begin(9600);
FastLED.addLeds<CHIPSET, DATA_PIN>(leds, NUM_LEDS);
}

void loop() {
//poti1val = analogRead(poti1);
poti2val = analogRead(poti2);
//poti3val = analogRead(poti3);

//mapLeds = map(poti1val, 0, 1023, 0, NUM_LEDS);
hue = map(poti2val, 0, 1023, 0, 255);
//saturation = map(poti3val, 0, 1023, 0, 255);

//Serial.print(poti1val);
//Serial.print(" “);
Serial.print(poti2val);
Serial.print(” “);
//Serial.print(poti3val);
//Serial.print(” “);
Serial.print(mapLeds);
Serial.print(” “);
Serial.print(hue);
Serial.print(” ");
Serial.println(saturation);

FastLED.clear();
leds[mapLeds] = CHSV(hue, 255, 255);
FastLED.show();
delay(10);
}

your line:
//mapLeds = map(poti1val, 0, 1023, 0, NUM_LEDS);
is commented out. Which means mapLeds will be equal to zero, thus only the first pixel.

Consider using http://pastebin.com for posting large chunks of code.

In your previous code post you have two ‘for’ loops. The first making all the leds red. That loop should probably removed. Then your second ‘for’ loop is reading and writing a value, but you can’t just write the value to the pin like that and have it change the leds. You have to plug that into the leds with something like
leds[i] = CHSV(0,255, your_calculated_brightness_value_here); //this will be hue 0 = red, saturation 255 = full saturation, and whatever value (ie brightness) you’ve calculated or mapped to.

Thanks for the info, was actually able to figure something out for a change.

Hue and Brightness seem to work as planned…

Thanks again!

http://pastebin.com/mAMWmEds

If you’re still interested @Stefin_T ​, here is a stripped down version of my code with the hue and brightness stuff.

Always willing to learn when others will teach the ignorant (me)… did not see a link though.

Oops. :stuck_out_tongue: Here’s the link.

Awesome! It works great…

I noticed your code’s hue goes from green (through rainbow) back to green, while the code I posted goes from red (through rainbow) to red? Is doesn’t seem either code stipulates what hue to start with… wondered what dictates that?

Also, I was playing with having potA cycle through a rainbow of hues, go to black (simulating off), then all leds go to White… while having potB control brightness overall. That way one could ‘select’ a color or simply have white and control the brightness independently.

Would this be a correct way to go about it?

FastLED.clear();
for(int dot = 0; dot < NUM_LEDS; dot++) {
if (POT_HUE_VALUE <= 1)
{
leds[dot] = CRGB::White;
FastLED.setBrightness (brightness);
leds[dot].fadeLightBy( 150 );
//Decreased white, it overpowered hue range
}
else if (POT_HUE_VALUE <= 25)
{
leds[dot] = CRGB::Black;
}
else
{
leds[dot].setHSV(hue,255,brightness);
}
}
FastLED.show();
delay(10);
}

@Stefin_T , sorry for delayed response. I’m not sure about the hue starting at red vs green, but my initial guess would be a difference in RGB ordering for our strips maybe?
I like your idea of having the white option. Another thing you could do when checking the “hue” potentiometer value is use If statements with “logical and” boolean operators. Example:

int lowCutoff = 1;
int midCutoff = 500;
int highCutoff = 1000;

if (POT_HUE_VALUE <= lowCutoff)
{
do low cutoff stuff
}
else if (POT_HUE_VALUE > lowCutoff && POT_HUE_VALUE <= midCutoff)
{
do low to mid cutoff stuff
}
else if (POT_HUE_VALUE > midCutoff && POT_HUE_VALUE <= highCutoff)
{
do mid to high cutoff stuff
}
else // Value is above highCutoff.
{
do above high cutoff stuff
}

To deal with White being too bright compared to hue colors, in the checkKnobs() function you could modify the brightness part a bit. Since you just checked and found the hue value, you can then use that value in a check when calculating the brightness. Something like:

potValB = analogRead(potPinB); // Read potentiometer B (for brightness).
if (potValA <= lowCutoff) { // If true it means you want to display White instead of a hue.
// So here we could divide by whatever looks correct to reduce the brightness when showing White.
brightness = map(potValB, 0, 1023, 0, (MASTER_BRIGHTNESS/1.7) ); // Divide master brightness by some amount.
} else {
brightness = map(potValB, 0, 1023, min_brightness, MASTER_BRIGHTNESS);
}
FastLED.setBrightness(brightness); // Set master brightness based on potentiometer position.

Thank you very much! I appreciate you taking the time to answer bonehead questions…