Help me achieving this effect through pinout

Trying to achieve this kind of effect as show on video at 5:37 time here LED chaser with 32 effects |led patterns with Arduino | Code in Discription - YouTube

Diagram + Code + Simulation here - https://wokwi.com/arduino/projects/311257068880265793

I tried modifying the code which I found over internet (link at the end of this post). But output not working as expected, please help me fixing the code

#define t1  20
int nanoPin[16] = {
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  10,
  11,
  12,
  13,
  14,
  15,
  16,
  17
};
int chCount = sizeof(nanoPin) / sizeof(int);

void setup() {
  for (int op; op < chCount; op++) {
    pinMode(nanoPin[op], OUTPUT);
    delay(10);
  }
}



void loop(){
 
 for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin], HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+1, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+1, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+2, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+2, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+3, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+3, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+4, LOW);
  delay(t1);
  }
    for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+4, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+5, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+5, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+6, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+6, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+7, LOW);
  delay(t1);
  }
   for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+7, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+8, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+8, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+9, LOW);
  delay(t1);
  }  
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+9, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+10, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+10, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+11, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+11, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+12, LOW);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+12, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+13, LOW);
  delay(t1);
  }  
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+13, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+14, LOW);
  delay(t1);
  }  
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+14, HIGH);
  delay(t1);
  digitalWrite(nanoPin[pin]+15, LOW);
  delay(t1);
  }  
  for(int pin = chCount; pin >= 0; pin--)
  {
  digitalWrite(nanoPin[pin]+15, HIGH);
  delay(t1);
  }
  for(int pin = chCount; pin >= 0; pin--)
  {
    digitalWrite(nanoPin[pin], LOW);
  delay(t1);
    }
   
   }

Note: Code found random on internet. Trying to get the effect_5().
Arduino code - 8 effects led chaser Code.txt - Google Drive

Post you code in code tags.

What?

Please, provide a better description of the issue.

Are you wanting me to write the code for you or do you want to try to figure it out yourself but just need hints?

One we figure out what you need gcjr will be along to write the code for you.

Output is not working as expected I have added the simulator link for the output.

Tell me where I am wrong?

I have shared the code also.

What output are you experiencing?
What output are you expecting?

LED should glow like this..
(left to right order)
1
12
123
1234
12345
123456
1234567....
....

Can you please visit the simulator link please.
Expecting effect like that but it's working only till 4th led.

Better written as

const int chCount = sizeof(nanoPin) / sizeof(nanoPin[0]);

Need to initialize op. There is no guarantee is will be zero to begin with

for (int op=0; op < chCount; op++) {

You are going out of bounds. You access array elements from 0..chCount-1
You do this multiple places...

Help me fixing this..
Code updated still not working..

In every for loop inside the loop function you access pin+1, you cannot do this because at the top of the loop you will try to access an item outside your array.

I found this a cool challenge so I fixed it for you, and removed most of your for loops at the same time

1 Like

Hello
Post your sketch well formated, with comments and in code tags "</>" to see how we can help.

Thanks mate, it's working as expected. :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.