Need guidance on programming RGB LED tape - indicator of intensity

Hi!

I would like to ask for help with my project. I am currently stuck at writing code or actually the idea how to write it.

I am using:

  • WS2813 RGB Led tape (45 leds)
  • potentiometer
  • Arduino Nano.

I want to indicate the value on potentiometer with LED tape. Leds from 0 to 45 have fixed colors from led(0)-red ->over orange->over yellow->to led(45)-green. And with potentiometer I want to turn ON number of leds depending on value on potentiometer.
Example:
-when potentiometer is in middle position, only 0 to 20 leds are turned ON and they are shading from red to orange
-when potentiometer is in right position, all leds are ON and they are shading from red->orange->yellow->to green

Best regards!
Matic

My code:

#include <FastLED.h>

#define LED_PIN  7
#define NUM_LEDS 45

CRGB leds[NUM_LEDS];

void setup()
{
  FastLED.addLeds<WS2813, LED_PIN, GRB>(leds, NUM_LEDS);
}

void loop()
{
  leds[0]=CRGB(255,0,0);
  leds[1]=CRGB(255,10,0);
  leds[2]=CRGB(255,20,0);
  leds[3]=CRGB(255,31,0); 
  leds[4]=CRGB(255,42,0);
  leds[5]=CRGB(255,53,0);
  leds[6]=CRGB(255,64,0);
  leds[7]=CRGB(255,75,0);
  leds[8]=CRGB(255,86,0);
  leds[9]=CRGB(255,97,0);
  leds[10]=CRGB(255,108,0);
  leds[11]=CRGB(255,118,0);
  leds[12]=CRGB(255,128,0);
  leds[13]=CRGB(255,139,0);
  leds[14]=CRGB(255,150,0);
  leds[15]=CRGB(255,161,0);
  leds[16]=CRGB(255,172,0);
  leds[17]=CRGB(255,181,0);
  leds[18]=CRGB(255,191,0);
  leds[19]=CRGB(255,201,0);
  leds[20]=CRGB(255,211,0);
  leds[21]=CRGB(255,221,0);
  leds[22]=CRGB(255,232,0);
  leds[23]=CRGB(255,243,0);
  leds[24]=CRGB(255,255,0);
  leds[25]=CRGB(240,255,0);
  leds[26]=CRGB(230,255,0);
  leds[27]=CRGB(220,255,0);
  leds[28]=CRGB(200,255,0);
  leds[29]=CRGB(190,255,0);
  leds[30]=CRGB(170,255,0);
  leds[31]=CRGB(160,255,0);
  leds[32]=CRGB(150,255,0);
  leds[33]=CRGB(140,255,0);
  leds[34]=CRGB(120,255,0);
  leds[35]=CRGB(110,255,0);
  leds[36]=CRGB(90,255,0);
  leds[37]=CRGB(80,255,0);
  leds[38]=CRGB(60,255,0);
  leds[39]=CRGB(50,255,0);
  leds[40]=CRGB(30,255,0);
  leds[41]=CRGB(20,255,0);
  leds[42]=CRGB(0,255,0);
  leds[43]=CRGB(0,255,0);
  leds[44]=CRGB(0,255,0);
  leds[45]=CRGB(0,255,0);
  FastLED.show();
}

You might want to use a scale.

If you have 4 LED’s you might divide the 5V or 3.3V into 4. When the potentiometer is 0V, all LED’s off, 1 LED on when pot at =< 5V/4, 2 LED’s on at =<5V/2, 3 LED’s when pot at =<4V/3, and so on and so forth.