Led fading using Array function

Hey Mates,
I wanted to simulate the Dawn light with my arduino Uno using array implementation.
I desired to change the brightness of the LEDs using fade effect( Smoothly and keep it unchanged until the next function called out) from 0 brightness to specific values in array ( it means specific brightness for each LED).
I wrote my code and compiled it but unfortunately nothing happens when I upload it to my device.
The device is already connected and I have tested some other on/off led codes.
Here is my pre-code:

//Dawn Light Simulation
int LEDArray = {3, 5, 6, 9, 10, 11};
int LedNum = 6;
int i;
int j;

int Dawn = {30, 20, 20, 20, 100, 0};

int Current = {0, 0, 0, 0, 0, 0};
unsigned long time_for_fadestep;
#define Fade_Interval 1200;

void setup() {

for (int i = 0; i < LedNum; i++)
pinMode(LEDArray[i], OUTPUT);

}

void DawnMode()
{
if (millis() > time_for_fadestep) {
time_for_fadestep = millis() + Fade_Interval;
for (int j = 0; j < LedNum; j++){
if (Dawn[j] > Current[j]) Current[j++];
if (Dawn[j] < Current[j]) Current[j--];
analogWrite(LEDArray[j], Current[j]);

}

}
}
void loop() {
DawnMode();
delay(5000);
}

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

Hello, and many appreciate for you note, I will do it certainly

Why are you messing about with the for loop index inside the for loop?
It looks like a crazy thing to do.
What are you trying to achieve?

The current array always seems to have zero in it and it never changes.

Please also run auto-format on your code using ctrl-T in the IDE editor, to properly highlight the code blocks.

Hello Mike,
The reason of using For() is to comparing each index's value and change the value in the Current[j] array.
If I remove For() , it just compare the values and does not increment or decrement the values. it's working now,
with some updates I could make the transition between values smoothly.

For the sake of others who might come across this thread in the future can you post your finished code please.

Having read the forum instructions for posting code and everything else.

I'm making some updates, and found some bugs as well, I will share it tomorrow