Report abuse

#define A 2
#define B 3
#define C 4
#define D 5

#define DELAY 500

int c[4][3][2] =
{
  { {A, D}, {A, C}, {A, B} },
  { {D, A}, {C, A}, {B, A} },
  { {C, D}, {B, D}, {B, C} },
  { {D, C}, {D, B}, {C, B} }
};

int frames[][4] =
{
  { 0b111,
    0b000,
    0b000,
    0b000
  },

  { 0b000,
    0b111,
    0b000,
    0b000
  },

  { 0b000,
    0b000,
    0b111,
    0b000
  },

  { 0b000,
    0b000,
    0b000,
    0b111
  },

  { 0b001,
    0b001,
    0b001,
    0b001
  },

  { 0b010,
    0b010,
    0b010,
    0b010
  },

  { 0b100,
    0b100,
    0b100,
    0b100
  }
};

void setup()
{
  pinMode( A, INPUT );
  pinMode( B, INPUT );
  pinMode( C, INPUT );
  pinMode( D, INPUT );
}

void display( int frame[4], int duration )
{
  int times = 0;
  int x = 0;
  int y = 0;

  while( times < duration )
  {

  for( y = 0; y < 4; y++ )  
  {
    for( x = 0; x < 3; x++ )
    {
      setup();
      if( frame[y] & (0b100 >> x) )
      {
        light( c[y][x] );
        delayMicroseconds(DELAY);
        times++;
      }
    }
  }

  }
}
void light( int pins[2] )
{
  pinMode( pins[0], OUTPUT );
  digitalWrite( pins[0], HIGH );

  pinMode( pins[1], OUTPUT );
  digitalWrite( pins[1], LOW );
}

void test( int pins[2] )
{
  setup();
  light(pins);
  delay(500);
}

void test_loop()
{
  test(c[0][0]);
  test(c[0][1]);
  test(c[0][2]);

  test(c[1][0]);
  test(c[1][1]);
  test(c[1][2]);

  test(c[2][0]);
  test(c[2][1]);
  test(c[2][2]);

  test(c[3][0]);
  test(c[3][1]);
  test(c[3][2]);
}

void loop()
{
  int i;

  for( i = 0; i < 7; i++ )
  {
    display( frames[i], 2000 );
  }
}