LED Fade Series Using Potentiometer

Hey guys, really new to Arduino (1 week) and trying an LED project!

I would like to have a series of LED’s (on PWM outputs), use a potentiometer to fade up the series from LED 1-5. LED 1 would fade from 0-255, then when it hits max value, LED 2 would begin its fade from 0-255 and so on throughout each LED. I’ve accomplished this on another project using digitalWrite for HIGH/LOW values, so they are either on or off and can produce a series effect, however I would like to see if it’s possible to make each LED fade from min-max value before the next one turns on, then reverse the effect as the pot goes back down. (Essentially this will be a precursor to using a microphone as input for a PFL, and the LED’s will show the input volume level visually)

Currently, when I run this program below, the first LED1 will fade up perfectly, however when it reaches max value, the next LED2 will turn on FULL, drop to minimum, and both LED’s will fade up with the pot. Once it reaches max, again the next LED will turn on FULL, then drop to minimum then all LED’s fade up, etc. I assume I’m missing some lines of code to tell the LED’s their min and maximum values, or do I need thresholds? I’m trying to make my code as short and simple as possible without having to write endless unnecessary lines. Hoping the awesome arduino community can give me some tips. Let me know if this is in the wrong forum area. Cheers guys.
P.S I have attached a schematic of my circuitry and wiring as well

int timer = 2;                       // delay in milliseconds
int ledPins [] { 5, 6, 9, 10, 11};   // led array output to PWM pins
int pinCount = 5;                    // amount of pins
const int potInput = A0;             // Pot input on pin A0
int outputValue = 0;                

void setup() {                               
for (int pin = 0; pin < pinCount; pin++) {    
  pinMode (ledPins[pin], OUTPUT);              // set Led array as Output
  }
  Serial.begin(9600);
}

void loop() {
 int sensorInput = analogRead(potInput);
     outputValue = map(sensorInput, 0, 1023, 0, 255);   // Read  input and map to led output values
   for (int pin = 0; pin < pinCount; pin++)                    
  {
    if ((pin * 51) < outputValue)                       // Used 255 divided by number of outputs (5)
    {
      analogWrite(pin[ledPins], sensorInput);
    }
    else
    {
      digitalWrite(pin[ledPins], LOW);                // pins above value don't turn on yet
    }
  }
   delay(timer);
   Serial.println(sensorInput);
}

Are you sure you mean ‘pin[ledpins]’? The variable ‘pin’ doesn’t look like an array to me. See array - Arduino Reference

Steve

How many times are you going to post this same question? LED Fade Series Using Potentiometer - Project Guidance - Arduino Forum

Cross posting is against the rules. Pick one forum and stick to it.

Steve

I assumed I posted in the wrong forum as it's more of a project question than a programming specific question. I didn't realise you can't delete posts until after and will ensure I stick to one forum from now on. Thanks steve

Hi Steve,
I changed the code for the analogWrite and sensorInput on the below lines and the array works.
For e.g When I turn the pot, each LED turns on in series from 1-5 as it hits the correct analog input value from the pot. Just not sure how to turn the digital HIGH/LOW into a 0-255 fade for each individual LED in series as per original question. Thanks!

 if ((pin * 51) < outputValue)                       // Used 255 divided by number of outputs (5)
    {
      digitalWrite(pin[ledPins], HIGH);
    }

Cross posts merged.