int led[]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18};
int min_speed=20;
int max_speed=300;
int delay_Value;
void read_pot()
{
  delay_Value=analogRead(A5);
  delay_Value=map(delay_Value,0,1023,min_speed,max_speed);
}
void led_row(int xx, int yy)
{
  for(int i=0; i<6;i++)
  digitalWrite(led[i+xx*6-6],yy);
}
void led_col(int xx, int yy)
{
  for(int i=0; i<3;i++)
  digitalWrite(led[xx-1+i*6],yy);
}
void setup() 
{
 for(int i=0; i<18;i++)
 pinMode(led[i],OUTPUT);
 pinMode(A5,INPUT);
}

void loop() 
{
 // effect1();
  //effect2();
 // effect3();
  //effect4();
 // effect5();
  //effect6();
  //effect7();
  effect8();
}


void effect1()
{
  for(int i=0; i<18;i++)
  {
    digitalWrite(led[i],HIGH);
    delay(delay_Value);
    digitalWrite(led[i],LOW);
    read_pot();
  }
}
void effect2()
{
  read_pot();
  led_row(1, 1);
  delay(delay_Value);
  led_row(1, 0);
  led_row(2, 1);
  delay(delay_Value);
  led_row(2, 0);
  led_row(3, 1);
  delay(delay_Value);
  led_row(3, 0);
}
void effect3()
{
  read_pot();
  for(int z=1;z<7;z++)
  {
    led_col(z, 1);
    delay(delay_Value);
    led_col(z, 0);
  }
}
void effect4()
{
  read_pot();
  int r=random(1,7);
  for(int z=1;z<=r;z++)
  {
    led_col(z, 1);
    delay(delay_Value);
  }
   for(int z=r;z>=1; z--)
  {
    led_col(z, 0);
    delay(delay_Value);
  }
  delay(delay_Value);
}
void effect5()
{
  read_pot();
  int r=random(1,6);
  for(int z=6;z>=r;z--)
  {
    led_col(z, 1);
    delay(delay_Value);
    read_pot();
  }
   for(int z=r;z<=6; z++)
  {
    led_col(z, 0);
    delay(delay_Value);
    read_pot();
  }
  delay(delay_Value);
}
void effect6()
{
  read_pot();
  led_row(1,1);
  led_row(2,0);
  led_row(3,1);
  digitalWrite(led[6],1);
  digitalWrite(led[11],1);
  delay(delay_Value*2);
  led_row(1,0);
  led_row(2,1);
  led_row(3,0);
  digitalWrite(led[6],0);
  digitalWrite(led[11],0);
  delay(delay_Value*2);
}
void effect7()
{
  read_pot();
  int r=random(1,7);
  led_col(r,1);
  delay(delay_Value);
  led_col(r,0);
  delay(delay_Value);
}
void effect8()
{
  read_pot();
  int r=random(1,4);
  led_row(r,1);
  delay(delay_Value);
  led_row(r,0);
  delay(delay_Value);
}