I have the same requirements, and solved it as below, with 6 working lines. The countPins output a normal binary sequence up to whatever is set by "switchbank"
int counter ;
int count0 ;
int count1 ;
int count2 ;
int count3 ;
int count4 ;
int countPin0 = 7;
int countPin1 = 8;
int countPin2 = 9;
int countPin3 = 13;
int countPin4 = 14;
int switchbanks = 32;
void setup()
{
pinMode(countPin0, OUTPUT );
pinMode(countPin1, OUTPUT );
pinMode(countPin2, OUTPUT );
pinMode(countPin3, OUTPUT );
pinMode(countPin4, OUTPUT );
counter = 0;
Serial.begin(9600);
}
void loop ()
{
for ( counter = 0; counter <= switchbanks ; counter ++ ) {
if ( counter % 2 ) { count0 = HIGH; } else { count0 = LOW; }
if ( (counter / 2 ) % 2 ) { count1 = HIGH; } else { count1 = LOW;}
if ( ( counter / 4 ) % 2 ) { count2 = HIGH; } else { count2 = LOW;}
if ( (counter / 8 ) % 2 ) { count3 = HIGH; } else { count3 = LOW;}
if ( (counter / 16 ) % 2 ) { count4 = HIGH; } else { count4 = LOW;}
Serial.print ( "counter = " );
Serial.println ( counter );
Serial.print ( "count0 = " );
Serial.println ( count0 );
Serial.print ( "count1 = " );
Serial.println ( count1 );
Serial.print ( "count2 = " );
Serial.println ( count2 );
Serial.print ( "count3 = " );
Serial.println ( count3 );
Serial.print ( "count4 = " );
Serial.println ( count4 );
}
delay ( 1000 );
}