for learning purpose, what changes can make this code

int sensor1 = 2;
int sensor2 = 3;
int sensor3 = 4;
int out1 = 8;
int out2 = 9;
int out3 = 10;
int out4 = 11;
int out5 = 12;
int out6 = 13;
int out7 = A0;
int out8 = A1;
int out9 = A2;

int on_delay = 2000;
int off_delay = 1000;
int total_delay = 10000;
void setup() {
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);
  pinMode(out1, OUTPUT);
  pinMode(out2, OUTPUT);
  pinMode(out3, OUTPUT);
  pinMode(out4, OUTPUT);
  pinMode(out5, OUTPUT);
  pinMode(out6, OUTPUT);
  pinMode(out7, OUTPUT);
  pinMode(out8, OUTPUT);
  pinMode(out9, OUTPUT);
}

void loop() {
  if (digitalRead(sensor1) == HIGH) {

    digitalWrite (out1, HIGH);
    delay (on_delay);
    digitalWrite (out2, HIGH);
    delay (on_delay);
    digitalWrite (out3, HIGH);
    delay (on_delay);
    digitalWrite (out4, HIGH);
    delay (on_delay);
    digitalWrite (out5, HIGH);
    delay (on_delay);
    digitalWrite (out6, HIGH);
    delay (on_delay);
    digitalWrite (out7, HIGH);
    delay (on_delay);
    digitalWrite (out8, HIGH);
    delay (on_delay);
    digitalWrite (out9, HIGH);
    delay (total_delay);

    digitalWrite(out9, LOW);
    delay (off_delay);
    digitalWrite(out8, LOW);
    delay (off_delay);
    digitalWrite(out7, LOW);
    delay (off_delay);
    digitalWrite(out6, LOW);
    delay (off_delay);
    digitalWrite(out5, LOW);
    delay (off_delay);
    digitalWrite(out4, LOW);
    delay (off_delay);
    digitalWrite(out3, LOW);
    delay (off_delay);
    digitalWrite(out2, LOW);
    delay (off_delay);
    digitalWrite(out1, LOW);
    delay (off_delay);
  }

  if (digitalRead(sensor2) == HIGH) {

    digitalWrite (out9, HIGH);
    delay (on_delay);
    digitalWrite (out8, HIGH);
    delay (on_delay);
    digitalWrite (out7, HIGH);
    delay (on_delay);
    digitalWrite (out6, HIGH);
    delay (on_delay);
    digitalWrite (out5, HIGH);
    delay (on_delay);
    digitalWrite (out4, HIGH);
    delay (on_delay);
    digitalWrite (out3, HIGH);
    delay (on_delay);
    digitalWrite (out2, HIGH);
    delay (on_delay);
    digitalWrite (out1, HIGH);
    delay (total_delay);

    digitalWrite(out1, LOW);
    delay (off_delay);
    digitalWrite(out2, LOW);
    delay (off_delay);
    digitalWrite(out3, LOW);
    delay (off_delay);
    digitalWrite(out4, LOW);
    delay (off_delay);
    digitalWrite(out5, LOW);
    delay (off_delay);
    digitalWrite(out6, LOW);
    delay (off_delay);
    digitalWrite(out7, LOW);
    delay (off_delay);
    digitalWrite(out8, LOW);
    delay (off_delay);
    digitalWrite(out9, LOW);
    delay (off_delay);
  }
}

Auto-format would help.

And more appropriate constant datatypes.

Then get rid of the delays.

i mean , millis() function , if else statement, switch case , something like that

Yes, all of those things, probably. And at least an array

Do you know how ‘arrays’ are used? Do you understand how to use the BWD ‘blink without delay’ technique? Do you know how to use ‘switch/case’?

int outputArray1[] = {8,9,10,11,12,13};
int outputArray2[] = {13,12,11,10,9,8};

i tried something same above , but not possible

bijitha: int outputArray1[] = {8,9,10,11,12,13}; int outputArray2[] = {13,12,11,10,9,8};

i tried something same above , but not possible

Why not possible?

AWOL:
Why not possible?

Thanks ,

when i make first i got error so i leave it ,

now i created with array

int outputArray1[] = {8, 9, 10, 11, 12, 13};
int outputArray2[] = {13, 12, 11, 10, 9, 8};

int delayTime = 100;

int button1 = 2;
int button2 = 3;
void setup() {
  //initialise ledArray as outputs
  for (int i = 0; i < 10; i++) {
    for ( int j = 0; j < 10; j++) {

      pinMode(outputArray1[i], OUTPUT);
      pinMode(outputArray2[i], OUTPUT);
      pinMode(button1, INPUT);
      pinMode(button2, INPUT);
    }
  }
}
void loop() {
  if (digitalRead(button1) == HIGH) {
    //turn LEDs on from 0-7
    for (int i = 0; i <= 7; i++)
    {
      digitalWrite(outputArray1[i], HIGH);
      delay(delayTime * 6);

    }

    //turn LEDs off from 7-0
    for (int i = 7; i >= 0; i--)
    {
      digitalWrite(outputArray1[i], LOW);
      delay(delayTime);
    }
  }

  if (digitalRead(button2) == HIGH) {
    //turn LEDs on from 0-7
    for (int j = 0; j <= 7; j++)
    {
      digitalWrite(outputArray2[j], HIGH);
      delay(delayTime * 6);

    }

    //turn LEDs off from 7-0
    for (int j = 7; j >= 0; j--)
    {
      digitalWrite(outputArray2[j], LOW);
      delay(delayTime);
    }
  }

}
}

any another suggestion

So rather than fix it, you left it?

AWOL: So rather than fix it, you left it?

because i am not sure ,i am only in bigging stage

You could've asked for advice.

if (digitalRead(sensor1) == HIGH) {

What happens if you let go of the switch, do you want things to restart ‘or’ do you want things to continue?

Are you sure you want two switches controlling the same outputs.

Edit:

Are you okay with code that blocks sketch progression, as it is now, or do you eventually want to see multiple things occur at the same time?

  for (int i = 0; i < 10; i++) {
    for ( int j = 0; j < 10; j++) {

      pinMode(outputArray1[i], OUTPUT);
      pinMode(outputArray2[i], OUTPUT);
      pinMode(button1, INPUT);
      pinMode(button2, INPUT);
    }
  }

Why two nested for loops ?

This might give some ideas how your current sketch can be changed.

However your delay() is blocking sketch code progression.

To be tested:

int sensor1 = 2;
int sensor2 = 3;
int sensor3 = 4;

//8 thru 16 are outputs

int on_delay    = 1000;
int off_delay   = 500;
int total_delay = 2000;

//**********************************************************************
void setup()
{
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);

  for (byte x = 8; x <= 16; x++)
  {
    pinMode(x, OUTPUT);
  }

} //END of setup()

//**********************************************************************
void loop()
{
  //*********************************************
  if (digitalRead(sensor1) == HIGH)
  {
    for (byte x = 8; x <= 16; x++)
    {
      digitalWrite (x, HIGH);
      delay (on_delay);
    }

    delay (total_delay);

    for (byte x = 16; x >= 8; x--)
    {
      digitalWrite (x, LOW);
      delay (off_delay);
    }

  } //END of    if (digitalRead(sensor1) == HIGH)

  //*********************************************
  if (digitalRead(sensor2) == HIGH)
  {
    for (byte x = 16; x >= 8; x--)
    {
      digitalWrite (x, HIGH);
      delay (on_delay);
    }

    delay (total_delay);

    for (byte x = 8; x <= 16; x++)
    {
      digitalWrite (x, LOW);
      delay (off_delay);
    }

  } //END of    if (digitalRead(sensor2) == HIGH)



} //END of loop()

//**********************************************************************

https://youtu.be/-FdmAVHk-Ao

need to work like this

2019-04-20_9-26-48.jpg

int sensor1 = 2;
int sensor2 = 3;
int sensor3 = 4;

//8 thru 16 are outputs   A0 = 14, A1 = 15, A3 = 16 on an Arduino UNO

int on_delay    = 1000;
int off_delay   = 500;
int total_delay = 2000;

//**********************************************************************
void setup()
{
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);

  for (byte x = 8; x <= 16; x++)
  {
    pinMode(x, OUTPUT);
  }

} //END of setup()

//**********************************************************************
void loop()
{
  //*********************************************
  if (digitalRead(sensor1) == HIGH)
  {
    for (byte x = 8; x <= 16; x++)
    {
      digitalWrite (x, HIGH);
      delay (on_delay);
    }

    delay (total_delay);

    for (byte x = 16; x >= 8; x--)
    {
      digitalWrite (x, LOW);
      delay (off_delay);
    }

  } //END of    if (digitalRead(sensor1) == HIGH)

  //*********************************************
  if (digitalRead(sensor2) == HIGH)
  {
    for (byte x = 16; x >= 8; x--)
    {
      digitalWrite (x, HIGH);
      delay (on_delay);
    }

    delay (total_delay);

    for (byte x = 8; x <= 16; x++)
    {
      digitalWrite (x, LOW);
      delay (off_delay);
    }

  } //END of    if (digitalRead(sensor2) == HIGH)


} //END of loop()

//**********************************************************************

Using arrays:

const byte sensor1 = 2;
const byte sensor2 = 3;
const byte sensor3 = 4;

const byte LEDpins[] = {8, 9, 10, 11, 12, 13, A0, A1, A2};

int on_delay    = 1000;
int off_delay   = 500;
int total_delay = 2000;

//**********************************************************************
void setup()
{
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(sensor3, INPUT);

  for (byte x = 0; x <= sizeof(LEDpins) - 1; x++)
  {
    pinMode(LEDpins[x], OUTPUT);
  }

} //END of setup()

//**********************************************************************
void loop()
{
  //*********************************************
  if (digitalRead(sensor1) == HIGH)
  {
    for (char x = 0; x <= sizeof(LEDpins) - 1; x++)
    {
      digitalWrite (LEDpins[x], HIGH);
      delay (on_delay);
    }

    delay (total_delay);

    for (char x = sizeof(LEDpins) - 1; x >= 0; x--)
    {
      digitalWrite (LEDpins[x], LOW);
      delay (off_delay);
    }

  } //END of    if (digitalRead(sensor1) == HIGH)

  //*********************************************
  if (digitalRead(sensor2) == HIGH)
  {
    for (char x = sizeof(LEDpins) - 1; x >= 0; x--)
    {
      digitalWrite (LEDpins[x], HIGH);
      delay (on_delay);
    }

    delay (total_delay);

    for (char x = 0; x <= sizeof(LEDpins) - 1 ; x++)
    {
      digitalWrite (LEDpins[x], LOW);
      delay (off_delay);
    }

  } //END of    if (digitalRead(sensor2) == HIGH)

} //END of loop()

//**********************************************************************