controlling adressable leds w/ potentiometers

hi forum

im pretty new to coding but so far i've managed to scramble by and figured out whatever problems i've had using the forums, youtube, etc. Right now im am working on a animatronics head, its pretty much 4 servos controlled by 2 analog joysticks (so essentially 4 potentiometers), thats working fine, but now i also want to control the brightness of some adressable leds, using the same 4 pots.

since the joystick''7servo setup is working pretty well, i've setup another arduino w/ a couple of pots and the led-strip so i can mess around without screwing up any of my working code :slight_smile:

so what im trying to achive is pot1 controlling the brightness of the first led, pot2 controlling brightness of second led, etc.
also i have a seperate pot controlling the color.

controlling color works, but both pot1 and pot2 control both leds. can anyone point me to where im off?:slight_smile:

thanks in advance and i hope my non-native-english is somewhat understandable

#include <FastLED.h>

#define LED_PIN 10              // digital out to leds
#define NUM_LEDS 2
#define COLOR_ORDER RGB
#define LED_TYPE WS2811

const int brightnessInPin = A2;  // The Analog input pin that the brightness control potentiometer1 is attached to.
const int brightnessInPinTo = A4; // The Analog input pin that the brightness control potentiometer2 is attached to.

const int colorInPin = A3;      // The Analog input pin that the colour control potentiometer is attached to.

struct CRGB leds[NUM_LEDS];

void setup() {
  delay(3000);

  LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

}

void loop() {

  int mappedColor;

  for (int i = 0; i < NUM_LEDS; i++) {
    mappedColor = map(analogRead(colorInPin), 0, 1023, 0, 255);

    leds[i] = CHSV(mappedColor, 255, 255);



    for (int i = 0; i < 1; i++)
      if (analogRead(brightnessInPin) < 100)FastLED.setBrightness(50);
    if ((analogRead(brightnessInPin) >= 100) && (analogRead(brightnessInPin) < 200))FastLED.setBrightness(100);
    if ((analogRead(brightnessInPin) >= 200) && (analogRead(brightnessInPin) < 300))FastLED.setBrightness(150);
    if ((analogRead(brightnessInPin) >= 300) && (analogRead(brightnessInPin) < 400))FastLED.setBrightness(200);
    if ((analogRead(brightnessInPin) >= 400) && (analogRead(brightnessInPin) < 1023))FastLED.setBrightness(255);


    for (int i = 1; i < 2; i++)
      if (analogRead(brightnessInPinTo) < 100)FastLED.setBrightness(50);
    if ((analogRead(brightnessInPinTo) >= 100) && (analogRead(brightnessInPinTo) < 200))FastLED.setBrightness(100);
    if ((analogRead(brightnessInPinTo) >= 200) && (analogRead(brightnessInPinTo) < 300))FastLED.setBrightness(150);
    if ((analogRead(brightnessInPinTo) >= 300) && (analogRead(brightnessInPinTo) < 400))FastLED.setBrightness(200);
    if ((analogRead(brightnessInPinTo) >= 400) && (analogRead(brightnessInPinTo) < 1023))FastLED.setBrightness(255);

    FastLED.show();

  }


}

tried another approach, realised i had enough free pins so ended up splitting the strip to seperate arrays..

this is probably now the moste elegant coding, but seems to work for now.. if anybody have suggestions on improvements i would love some pointers :slight_smile:

new code:

#include <FastLED.h>

#define LED_PIN1 10              // digital out to leds
#define LED_PIN2 11 
#define NUM_LEDS 7
#define COLOR_ORDER RGB
#define LED_TYPE WS2811

const int brightnessInPin = A1;  // The Analog input pin that the brightness control potentiometer1 is attached to.
const int brightnessInPin2 = A2; // The Analog input pin that the brightness control potentiometer2 is attached to.

const int colorInPin = A0;      // The Analog input pin that the colour control potentiometer is attached to.

CRGB leds1[NUM_LEDS];
CRGB leds2[NUM_LEDS];
void setup() {
  delay(3000);

  LEDS.addLeds<LED_TYPE, LED_PIN1, COLOR_ORDER>(leds1, NUM_LEDS).setCorrection(TypicalLEDStrip);
  LEDS.addLeds<LED_TYPE, LED_PIN2, COLOR_ORDER>(leds2, NUM_LEDS).setCorrection(TypicalLEDStrip);
  FastLED.setBrightness(100);
}

void loop() {
    
    int mappedColor;
    int Bright1;
    int Bright2;
    
    for (int i = 0; i < NUM_LEDS; i++) {
      
    mappedColor = map(analogRead(colorInPin), 0, 1023, 0, 255);

   if ((analogRead(brightnessInPin) >= 0) && (analogRead(brightnessInPin) < 102))Bright1=255;
   if ((analogRead(brightnessInPin) >= 102) && (analogRead(brightnessInPin) < 204))Bright1=200;
   if ((analogRead(brightnessInPin) >= 204) && (analogRead(brightnessInPin) < 306))Bright1=150;
   if ((analogRead(brightnessInPin) >= 306) && (analogRead(brightnessInPin) < 408))Bright1=100;
   if ((analogRead(brightnessInPin) >= 408) && (analogRead(brightnessInPin) < 500))Bright1=50;
   if ((analogRead(brightnessInPin) >= 500) && (analogRead(brightnessInPin) < 602))Bright1=50;
   if ((analogRead(brightnessInPin) >= 602) && (analogRead(brightnessInPin) < 704))Bright1=100;
   if ((analogRead(brightnessInPin) >= 704) && (analogRead(brightnessInPin) < 806))Bright1=150;
   if ((analogRead(brightnessInPin) >= 806) && (analogRead(brightnessInPin) < 908))Bright1=200;
   if ((analogRead(brightnessInPin) >= 908) && (analogRead(brightnessInPin) < 1023))Bright1=255;

   if ((analogRead(brightnessInPin2) >= 0) && (analogRead(brightnessInPin2) < 102))Bright2=255;
   if ((analogRead(brightnessInPin2) >= 102) && (analogRead(brightnessInPin2) < 204))Bright2=200;
   if ((analogRead(brightnessInPin2) >= 204) && (analogRead(brightnessInPin2) < 306))Bright2=150;
   if ((analogRead(brightnessInPin2) >= 306) && (analogRead(brightnessInPin2) < 408))Bright2=100;
   if ((analogRead(brightnessInPin2) >= 408) && (analogRead(brightnessInPin2) < 500))Bright2=50;
   if ((analogRead(brightnessInPin2) >= 500) && (analogRead(brightnessInPin2) < 602))Bright2=50;
   if ((analogRead(brightnessInPin2) >= 602) && (analogRead(brightnessInPin2) < 704))Bright2=100;
   if ((analogRead(brightnessInPin2) >= 704) && (analogRead(brightnessInPin2) < 806))Bright2=150;
   if ((analogRead(brightnessInPin2) >= 806) && (analogRead(brightnessInPin2) < 908))Bright2=200;
   if ((analogRead(brightnessInPin2) >= 908) && (analogRead(brightnessInPin2) < 1023))Bright2=255;

    leds1[i] = CHSV(mappedColor, 255, Bright1);
    leds2[i] = CHSV(mappedColor, 255, Bright2);
    }
   
    FastLED.show();
}

its pretty much 4 servos controlled by 2 analog joysticks (so essentially 4 potentiometers), thats working fine

You will find that the servo library is not compatible with the LED library. This is because when sending data to led strips the interrupts are disabled and this causes the servo pulses produced by the library to loose its timing.

The best way round this is to either use the Dot star type led strip or use an external servo driver board.

    for (int i = 0; i < 1; i++)  // are you JOKING? This sets i to 0, runs the first if(), sets i to 1 then quits.
      if (analogRead(brightnessInPin) < 100)FastLED.setBrightness(50); // this is the only line that is in that loop-but-not.

    if ((analogRead(brightnessInPin) >= 100) && (analogRead(brightnessInPin) < 200))FastLED.setBrightness(100);
    if ((analogRead(brightnessInPin) >= 200) && (analogRead(brightnessInPin) < 300))FastLED.setBrightness(150);
    if ((analogRead(brightnessInPin) >= 300) && (analogRead(brightnessInPin) < 400))FastLED.setBrightness(200);
    if ((analogRead(brightnessInPin) >= 400) && (analogRead(brightnessInPin) < 1023))FastLED.setBrightness(255);


    for (int i = 1; i < 2; i++)  // this loop runs values 0 and 1, but only the next line is looped.
      if (analogRead(brightnessInPinTo) < 100)FastLED.setBrightness(50);

    if ((analogRead(brightnessInPinTo) >= 100) && (analogRead(brightnessInPinTo) < 200))FastLED.setBrightness(100);
    if ((analogRead(brightnessInPinTo) >= 200) && (analogRead(brightnessInPinTo) < 300))FastLED.setBrightness(150);
    if ((analogRead(brightnessInPinTo) >= 300) && (analogRead(brightnessInPinTo) < 400))FastLED.setBrightness(200);
    if ((analogRead(brightnessInPinTo) >= 400) && (analogRead(brightnessInPinTo) < 1023))FastLED.setBrightness(255);

    FastLED.show();

  }
            // also every time you call analogRead() it takes 105+ millis. That's needless even to follow pot-twisting.

Even worse, in neither of those 2 for-next loops is the value of i used to address either led 0 or led 1.
The lines to set brightness are repeated even though they DO THE SAME THING.