Program creation

good evening I would like to ask how to connect or create a program I would like to control two LED strips via two potentiometers, each with one potentiometer, eg via A0 and A1 via A0 I would have the program as I create another LED strip via A1 in advance Thank you

  1. #include "FastLED.h"
  • #define PIN_SLIDE_POT_A A0 // input pin of the slide pot
  1. #define MAX_SLIDE_POT_ANALGOG_READ_VALUE 700 // maximum voltage as analog-to-digital converted value, depends on the voltage level of the VCC pin. Examples: 5V = 1023; 3.3V ~700
  • #define NUM_LEDS 10 // add number of LEDs of your RGB LED strip
  1. #define PIN_LED 3 // digital output PIN that is connected to DIN of the RGB LED strip

  2. #define LED_COLOR CRGB::DarkOrchid // see Pixel reference · FastLED/FastLED Wiki · GitHub for a full list, e.g. CRGB::AliceBlue, CRGB::Amethyst, CRGB::AntiqueWhite...

  • CRGB rgb_led[NUM_LEDS]; // color array of the LED RGB strip

  • void setup() {

  1. Serial.begin(9600);
  • pinMode(PIN_SLIDE_POT_A, INPUT);
  1. FastLED.addLeds<WS2812B, PIN_LED>(rgb_led, NUM_LEDS);
  • Serial.println("Setup done.");
  1. }
  • void loop() {
  1. // 1) Analog value of slide pot is read

  2. int value_slide_pot_a = analogRead(PIN_SLIDE_POT_A);

  3. Serial.print("Slide Pot value: ");

  4. Serial.println(value_slide_pot_a);

  • // 2) Analog value is mapped from slide pot range (analog input value) to led range (number of LEDs)
  1. int num_leds_switchedon = map(value_slide_pot_a, 0, MAX_SLIDE_POT_ANALGOG_READ_VALUE, 0, NUM_LEDS);
  • // 3) Light up the LEDs
  1. // Only LEDs are switched on which correspond to the area left of the slide knob

  2. for (int i = 0; i < num_leds_switchedon; ++i) {

  3. rgb_led[i] = LED_COLOR;

  4. }

  5. // LEDs are switched off which correspond to the area right of the slide knob

  6. for (int i = num_leds_switchedon; i < NUM_LEDS; ++i) {

  7. rgb_led[i] = CRGB::Black;

  8. }

  9. FastLED.show();

  10. }

Read the forum guidelines to see how to properly post code and some hints on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Your code, as posted, is in one line when copied to the IDE. That makes it near impossible to read so I pass. Post the code properly and you may get some help.

What does the improperly posted code actually do? How does that differ from what you want?

WOW

Have never seen a sketch posted is such a manner.


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.

Use the </> icon from the ‘reply menu’ to attach the copied sketch.


Show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.

1 Like

It doesn't compile either.

...and it is not any kind of tutorial.

Flagged and reported.

Please post your code here, in code tags (the "</>" icon on the post editor toolbar)

  1. #include "FastLED.h"
  • #define PIN_SLIDE_POT_A A0 // input pin of the slide pot
  1. #define MAX_SLIDE_POT_ANALGOG_READ_VALUE 700 // maximum voltage as analog-to-digital converted value, depends on the voltage level of the VCC pin. Examples: 5V = 1023; 3.3V ~700
  • #define NUM_LEDS 10 // add number of LEDs of your RGB LED strip
  1. #define PIN_LED 3 // digital output PIN that is connected to DIN of the RGB LED strip

  2. #define LED_COLOR CRGB::DarkOrchid // see Pixel reference · FastLED/FastLED Wiki · GitHub for a full list, e.g. CRGB::AliceBlue, CRGB::Amethyst, CRGB::AntiqueWhite...

  • CRGB rgb_led[NUM_LEDS]; // color array of the LED RGB strip

  • void setup() {

  1. Serial.begin(9600);
  • pinMode(PIN_SLIDE_POT_A, INPUT);
  1. FastLED.addLeds<WS2812B, PIN_LED>(rgb_led, NUM_LEDS);
  • Serial.println("Setup done.");
  1. }
  • void loop() {
  1. // 1) Analog value of slide pot is read

  2. int value_slide_pot_a = analogRead(PIN_SLIDE_POT_A);

  3. Serial.print("Slide Pot value: ");

  4. Serial.println(value_slide_pot_a);

  • // 2) Analog value is mapped from slide pot range (analog input value) to led range (number of LEDs)
  1. int num_leds_switchedon = map(value_slide_pot_a, 0, MAX_SLIDE_POT_ANALGOG_READ_VALUE, 0, NUM_LEDS);
  • // 3) Light up the LEDs
  1. // Only LEDs are switched on which correspond to the area left of the slide knob

  2. for (int i = 0; i < num_leds_switchedon; ++i) {

  3. rgb_led[i] = LED_COLOR;

  4. }

  5. // LEDs are switched off which correspond to the area right of the slide knob

  6. for (int i = num_leds_switchedon; i < NUM_LEDS; ++i) {

  7. rgb_led[i] = CRGB::Black;

  8. }

  9. FastLED.show();

  10. }

Hi, @romanslovakia
To add code please click this link;

The way you have presented your code, it is very difficult to put in the IDE and test.
Line numbers are not needed.

Have you been able to compile your code?

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:
PS, This is how your code will be presented if you read the link I have provided.

#include "FastLED.h"
#define PIN_SLIDE_POT_A A0 // input pin of the slide pot
#define MAX_SLIDE_POT_ANALGOG_READ_VALUE 700 // maximum voltage as analog-to-digital converted value, depends on the voltage level of the VCC pin. Examples: 5V = 1023; 3.3V ~700
#define NUM_LEDS 10 // add number of LEDs of your RGB LED strip
#define PIN_LED 3 // digital output PIN that is connected to DIN of the RGB LED strip

#define LED_COLOR CRGB::DarkOrchid // see Pixel reference · FastLED/FastLED Wiki · GitHub for a full list, e.g. CRGB::AliceBlue, CRGB::Amethyst, CRGB::AntiqueWhite...

CRGB rgb_led[NUM_LEDS]; // color array of the LED RGB strip

void setup()
{
  Serial.begin(9600);
  pinMode(PIN_SLIDE_POT_A, INPUT);
  FastLED.addLeds<WS2812B, PIN_LED>(rgb_led, NUM_LEDS);
  Serial.println("Setup done.");
}
void loop()
{
  // 1) Analog value of slide pot is read
  int value_slide_pot_a = analogRead(PIN_SLIDE_POT_A);
  Serial.print("Slide Pot value: ");
  Serial.println(value_slide_pot_a);
  // 2) Analog value is mapped from slide pot range (analog input value) to led range (number of LEDs)
  int num_leds_switchedon = map(value_slide_pot_a, 0, MAX_SLIDE_POT_ANALGOG_READ_VALUE, 0, NUM_LEDS);
  // 3) Light up the LEDs
  // Only LEDs are switched on which correspond to the area left of the slide knob
  for (int i = 0; i < num_leds_switchedon; ++i)
  {
    rgb_led[i] = LED_COLOR;
  }
  // LEDs are switched off which correspond to the area right of the slide knob
  for (int i = num_leds_switchedon; i < NUM_LEDS; ++i)
  {
    rgb_led[i] = CRGB::Black;
  }
  FastLED.show();
}

I failed

I would like it to work on two LED strips with two potentiometers