int muxx[50]; int EN = 2; int S0 = 3; int S1 = 4; int S2 = 5; int S3 = 6; int Z = 7;
void mux( int s3, int s2, int s1, int s0 ){
digitalWrite ( S1, s1 );
digitalWrite ( S2, s2 );
digitalWrite ( S3, s3 );
digitalWrite ( S0, s0 );
}
#define rMux( ) digitalRead ( Z );
void readMux( ) { int p; mux( 0, 0, 0, 0 ); muxx[0] = rMux( ); mux( 0, 0, 0, 1 ); muxx[1] = rMux( ); mux( 0, 0, 1, 0 ); muxx[2] = rMux( ); mux( 0, 0, 1, 1 ); muxx[3] = rMux( ); mux( 0, 1, 0, 0 ); muxx[4] = rMux( ); mux( 0, 1, 0, 1 ); muxx[5] = rMux( ); mux( 0, 1, 1, 0 ); muxx[6] = rMux( ); mux( 0, 1, 1, 1 ); muxx[7] = rMux( ); mux( 1, 0, 0, 0 ); muxx[8] = rMux( ); mux( 1, 0, 0, 1 ); muxx[9] = rMux( ); mux( 1, 0, 1, 0 ); muxx[10] = rMux( ); mux( 1, 0, 1, 1 ); muxx[11] = rMux( ); mux( 1, 1, 0, 0 ); muxx[12] = rMux( ); mux( 1, 1, 0, 1 ); muxx[13] = rMux( ); mux( 1, 1, 1, 0 ); muxx[14] = rMux( ); mux( 1, 1, 1, 1 ); muxx[15] = rMux( ); Serial.print( "1..8 " ); for( int i = 0; i < 8; i++ ) { Serial.print( muxx[i] ); } Serial.println( " " ); Serial.print( "9..16 " ); for( int i = 8; i < 16; i++ ) { Serial.print( muxx[i] ); } Serial.println( " " ); }
void process( ) { if( muxx[0] == 1 ) { muxx[20] = 1; } else { muxx[20] = 0; } if( muxx[1] == 1 ){ muxx[21] = 2; } else { muxx[21] = 0; } if( muxx[2] == 1 ) { muxx[22] = 4; } else { muxx[22] = 0; } if( muxx[3] == 1 ) { muxx[23] = 8; } else { muxx[23] = 0; } if( muxx[4] == 1){ muxx[24] = 1; } else { muxx[24] = 0; } if( muxx[5] == 1 ) { muxx[25] = 2; } else { muxx[25] = 0; } if( muxx[6] == 1 ) { muxx[26] = 4; } else { muxx[26] = 0; } if( muxx[7] == 1 ){ muxx[27] = 8; } else { muxx[27] = 0; } if( muxx[8] == 1 ) { muxx[28] = 1; } else { muxx[28] = 0; } if( muxx[9] == 1 ) { muxx[29] = 2; } else { muxx[29] = 0; } if( muxx[10] == 1 ){ muxx[30] = 4; } else { muxx[30] = 0; } if( muxx[11] == 1 ) { muxx[31] = 8; } else { muxx[31] = 0; } muxx[32] = ( muxx[20] + muxx[21] + muxx[22] + muxx[23] ); muxx[33] = ( muxx[24] + muxx[25] + muxx[26] + muxx[27] ); muxx[34] = ( muxx[28] + muxx[29] + muxx[30] + muxx[31] ); Serial.print( "Dig I: " ); Serial.println( muxx[32] ); Serial.print( "Dig II: " ); Serial.println( muxx[33] ); Serial.print( "Dig III: " ); Serial.println( muxx[34] ); Serial.println( " " ); }
uint8_t zipNo(){
uint8_t a, b, c;
uint8_t x;
a=(muxx[32]*100);
b=(muxx[33]*10);
c=(muxx[34]*1);
x=(a+b+c);
Serial.print( "Num# = " );
Serial.println( x );
return x;
}
void setup( ) {
pinMode ( EN, 1 );
pinMode ( S0, 1 );
pinMode ( S1, 1 );
pinMode ( S2, 1 );
pinMode ( S3, 1 );
pinMode ( Z, 0 );
Serial.begin(9600);Serial.println("START");
}
void loop ( ) {
readMux();
process();
zipNo();
}