//#ifndef MUX_H
//#define MUX_H
/*
MUX_H
_ _ _ _ __ _ _
| \/ | | | \ \/ / | | | |
| |\/| | | | |\ / | |_| |
| | | | |_| |/ \ | _ |
|_| |_|\___//_/\_\___|_| |_|
|_____|
*/
/*
MULTIPLEXOR
_ ___ __ ________
__ _ ___
_ _
_ __
| \/ | | | | | |_ | _|| _ \| | | __|\ \/ / _ \ | _ \
| |\/| | | | | | | | | | | |_) | | | _| \ / | | || |) |
| | | | |_| | |___| | | |_| _ /| |___| |_ / \ |_| || _ <
|_| |_|\___/|_____|_| |____|_| |_____|_____/__/\__\___/|_| \_\
hef4051
_ _ _ _ _ _ _
| |__ _ / _| || | / _ \| ___|/ |
| '_ \ / _ \ |_| || |_| | | |___ \| |
| | | | / _| | |_| |__) | |
|_| |_|\___|_| |_| \___/|____/|_|
hef4067
_ _ _ _ _ _ ___
| |__ _ / | || | / _ \ / /|__ |
| '_ \ / _ \ |_| || |_| | | | '_ \ / /
| | | | / _| | |_| | () / /
|_| |_|\___|_| |_| \___/ \___/_/
*/
int EN51; int S151; int S251; int S351; int MUX51; int Z51;
void setMux51 ( int s1Pin, int s2Pin, int s3Pin, int enPin, int zInPin ) { EN51 = enPin; S151 = s1Pin; S251 = s2Pin; S351 = s3Pin; Z51 = zInPin; pinMode( EN51, 1 ); pinMode ( S151, 1 ); pinMode ( S251, 1 ); pinMode ( S351, 1 ); /*pinMode ( zInPin, 0 );*/ digitalWrite ( EN51, 0 ); Serial.begin(9600); Serial.println("START"); }
int EN67; int S167; int S267; int S367; int S467; int MUX67; int Z67;
void setMux67 ( int s1Pin, int s2Pin, int s3Pin, int s4Pin, int enPin, int zInPin ) { EN67 = enPin; S167 = s1Pin; S267 = s2Pin; S367 = s3Pin; S467 = s4Pin; Z67 = zInPin; pinMode( EN67, 1 ); pinMode ( S167, 1 ); pinMode ( S267, 1 ); pinMode ( S367, 1 ); pinMode ( S467, 1 ); /*pinMode ( zInPin, 0 );*/ digitalWrite ( EN67, 0 ); Serial.begin(9600); Serial.println("START"); }
void mux51 ( int s1, int s2, int s3 ) { digitalWrite ( S151, s1 ); digitalWrite ( S251, s2 ); digitalWrite ( S351, s3 ); delay ( 10 ); }
void mux67 ( int s1, int s2, int s3, int s4 ) { digitalWrite ( S167, s1 ); digitalWrite ( S267, s2 ); digitalWrite ( S367, s3 ); digitalWrite ( S467, s4 ); delay ( 10 ); }
int mux151; int mux251; int mux351; int mux451; int mux551; int mux651; int mux751; int mux851;
void printMux51( int tx ){ mux51( 0, 0, 0 ); mux151 = analogRead(MUX51); mux51( 0, 0, 1 ); mux251 = analogRead(MUX51); mux51( 0, 1, 0 ); mux351 = analogRead(MUX51); mux51( 0, 1, 1 ); mux451 = analogRead(MUX51); mux51( 1, 0, 0 ); mux551 = analogRead(MUX51); mux51( 1, 0, 1 ); mux651 = analogRead(MUX51); mux51( 1, 1, 0 ); mux751 = analogRead(MUX51); mux51( 1, 1, 1 ); mux851 = analogRead(MUX51); Serial.println( "_____________________" ); Serial.println( "__||____||____||__" ); Serial.print( mux151 ); Serial.print( " " ); Serial.print( mux251 ); Serial.print( " " ); Serial.print( mux351 ); Serial.print( " " ); Serial.print( mux451 ); Serial.println( " " ); Serial.println( "__||____||____||__" ); Serial.print( mux551 ); Serial.print( " " ); Serial.print( mux651 ); Serial.print( " " ); Serial.print( mux751 ); Serial.print( " " ); Serial.print( mux851 ); delay ( tx ); Serial.println( " " ); }
int mux167; int mux267; int mux367; int mux467; int mux567; int mux667; int mux767; int mux867; int mux967; int mux1067; int mux1167; int mux1267; int mux1367; int mux1467; int mux1567; int mux1667;
void printMux67( int tx ){ mux67( 0, 0, 0, 0 ); mux167 = analogRead(MUX67); mux67( 0, 0, 0, 1 ); mux267 = analogRead(MUX67); mux67( 0, 0, 1, 0 ); mux367 = analogRead(MUX67); mux67( 0, 0, 1, 1 ); mux467 = analogRead(MUX67); mux67( 0, 1, 0, 0 ); mux567 = analogRead(MUX67); mux67( 0, 1, 0, 1 ); mux667 = analogRead(MUX67); mux67( 0, 1, 1, 0 ); mux767 = analogRead(MUX67); mux67( 1, 1, 1, 0 ); mux867 = analogRead(MUX67); mux67( 1, 0, 0, 0 ); mux967 = analogRead(MUX67); mux67( 1, 0, 0, 1 ); mux1067 = analogRead(MUX67); mux67( 1, 0, 1, 0 ); mux1167 = analogRead(MUX67); mux67( 1, 0, 1, 1 ); mux1267 = analogRead(MUX67); mux67( 1, 1, 0, 0 ); mux1367 = analogRead(MUX67); mux67( 1, 1, 0, 1 ); mux1467 = analogRead(MUX67); mux67( 1, 1, 1, 0 ); mux1567 = analogRead(MUX67); mux67( 1, 1, 1, 1 ); mux1667 = analogRead(MUX67); Serial.println( "_____________________" ); Serial.println( "__||____||____||__" ); Serial.print( mux167 ); Serial.print( " " ); Serial.print( mux267 ); Serial.print( " " ); Serial.print( mux367 ); Serial.print( " " ); Serial.print( mux467 ); Serial.println( " " ); Serial.println( "__||____||____||__" ); Serial.print( mux567 ); Serial.print( " " ); Serial.print( mux667 ); Serial.print( " " ); Serial.print( mux767 ); Serial.print( " " ); Serial.print( mux867 ); delay ( tx ); Serial.println( " " ); Serial.println( "_____________________" ); Serial.println( "__||____||____||__" ); Serial.print( mux967 ); Serial.print( " " ); Serial.print( mux1067 ); Serial.print( " " ); Serial.print( mux1167 ); Serial.print( " " ); Serial.print( mux1267 ); Serial.println( " " ); Serial.println( "__||____||____||__" ); Serial.print( mux1367 ); Serial.print( " " ); Serial.print( mux1467 ); Serial.print( " " ); Serial.print( mux1567 ); Serial.print( " " ); Serial.print( mux1667 ); delay ( tx ); Serial.println( " " ); }
void readMux51 ( ){ mux51( 0, 0, 0 ); mux151 = analogRead( MUX51 ); mux51( 0, 0, 1 ); mux251 = analogRead( MUX51 ); mux51( 0, 1, 0 ); mux351 = analogRead( MUX51 ); mux51( 0, 1, 1 ); mux451 = analogRead( MUX51 ); mux51( 1, 0, 0 ); mux551 = analogRead( MUX51 ); mux51( 1, 0, 1 ); mux651 = analogRead( MUX51 ); mux51( 1, 1, 0 ); mux751 = analogRead( MUX51 ); mux51( 1, 1, 1 ); mux851 = analogRead( MUX51 ); }
void readMux67 ( ){ mux67( 0, 0, 0, 0 ); mux167 = analogRead( MUX67 ); mux67( 0, 0, 0, 1 ); mux267 = analogRead( MUX67 ); mux67( 0, 0, 1, 0 );mux367 = analogRead( MUX67 ); mux67( 0, 0, 1, 1 ); mux467 = analogRead( MUX67 ); mux67( 0, 1, 0, 0 ); mux567 = analogRead( MUX67 ); mux67( 0, 1, 0, 1 ); mux667 = analogRead( MUX67 ); mux67( 0, 1, 1, 0 ); mux767 = analogRead( MUX67 ); mux67( 0, 1, 1, 1 ); mux867 = analogRead( MUX67 ); mux67( 1, 0, 0, 0 ); mux967 = analogRead( MUX67 ); mux67( 1, 0, 0, 1 ); mux1067 = analogRead( MUX67 ); mux67( 1, 0, 1, 0 ); mux1167 = analogRead( MUX67 ); mux67( 1, 0, 1, 1 ); mux1267 = analogRead( MUX67 ); mux67( 1, 1, 0, 0 ); mux1367 = analogRead( MUX67 ); mux67( 1, 1, 0, 1 ); mux1467 = analogRead( MUX67 ); mux67( 1, 1, 1, 0 ); mux1567 = analogRead( MUX67 ); mux67( 1, 1, 1, 1 ); mux1667 = analogRead( MUX67 ); }
int readMux151( ){ mux51( 0, 0, 0); mux151 = analogRead( MUX51 ); return mux151; }
int readMux251( ){ mux51( 0, 0, 1); mux251 = analogRead( MUX51 ); return mux251; }
int readMux351( ){ mux51( 0, 1, 0); mux351 = analogRead( MUX51 ); return mux351; }
int readMux451( ){ mux51( 0, 1, 1); mux451 = analogRead( MUX51 ); return mux451; }
int readMux551( ){ mux51( 1, 0, 0); mux551 = analogRead( MUX51 ); return mux551; }
int readMux651( ){ mux51( 1, 0, 1); mux651 = analogRead( MUX51 ); return mux651; }
int readMux751( ){ mux51( 1, 1, 0); mux751 = analogRead( MUX51 ); return mux751; }
int readMux851( ){ mux51( 1, 1, 1); mux851 = analogRead( MUX51 ); return mux851; }
int readMux167( ){ mux67( 0, 0, 0, 0); mux167 = analogRead( MUX67 ); return mux167; }
int readMux267( ){ mux67( 0, 0, 0, 1); mux267 = analogRead( MUX67 ); return mux267; }
int readMux367( ){ mux67( 0, 0, 1, 0); mux367 = analogRead( MUX67 ); return mux367; }
int readMux467( ){ mux67( 0, 0, 1, 1); mux467 = analogRead( MUX67 ); return mux467; }
int readMux567( ){ mux67( 0, 1, 0, 0); mux567 = analogRead( MUX67 ); return mux567; }
int readMux667( ){ mux67( 0, 1, 0, 1); mux667 = analogRead( MUX67 ); return mux667; }
int readMux767( ){ mux67( 0, 1, 1, 0); mux767 = analogRead( MUX67 ); return mux767; }
int readMux867( ){ mux67( 0, 1, 1, 1); mux867 = analogRead( MUX67 ); return mux867; }
int readMux967( ){ mux67( 1, 0, 0, 0); mux967 = analogRead( MUX67 ); return mux967; }
int readMux1067( ){ mux67( 1, 0, 0, 1); mux1067 = analogRead( MUX67 ); return mux1067; }
int readMux1167( ){ mux67( 1, 0, 1, 0); mux1167 = analogRead( MUX67 ); return mux1167; }
int readMux1267( ){ mux67( 1, 0, 1, 1); mux1267 = analogRead( MUX67 ); return mux1267; }
int readMux1367( ){ mux67( 1, 1, 0, 0); mux1367 = analogRead( MUX67 ); return mux1367; }
int readMux1467( ){ mux67( 1, 1, 0, 1); mux1467 = analogRead( MUX67 ); return mux1467; }
int readMux1567( ){ mux67( 1, 1, 1, 0); mux1567 = analogRead( MUX67 ); return mux1567; }
int readMux1667( ){ mux67( 1, 1, 1, 1); mux1667 = analogRead( MUX67 ); return mux1667; }
bool digMux151; bool digMux251; bool digMux351; bool digMux451; bool digMux551; bool digMux651; bool digMux751; bool digMux851;
void digMux51( ){ readMux51(); if ( mux151 <= 63 ) { digMux151 = false; } if ( mux151 >= 959 ) { digMux151 = true; } if ( mux251 <= 63 ) { digMux251 = false; } if ( mux251 >= 959 ) { digMux251 = true; } if ( mux351 <= 63) { digMux351 = false; } if ( mux351 >= 959 ) { digMux351 = true; } if ( mux451 <= 63 ) { digMux451 = false; } if ( mux451 >= 959 ) { digMux451 = true; } if ( mux551 <= 63 ) { digMux551 = false; } if ( mux551 >= 959 ) { digMux551 = true; } if ( mux651 <= 63 ) { digMux651 = false; } if ( mux651 >= 959 ) { digMux651 = true; } if ( mux751 <= 63 ) { digMux751 = false; } if ( mux751 >= 959 ) { digMux751 = true; } if ( mux851 <= 63 ) { digMux851 = false; } if ( mux851 >= 959 ) { digMux851 = true; } }
bool digMux167; bool digMux267; bool digMux367; bool digMux467; bool digMux567; bool digMux667; bool digMux767; bool digMux867; bool digMux967; bool digMux1067; bool digMux1167; bool digMux1267; bool digMux1367; bool digMux1467; bool digMux1567; bool digMux1667;
void digMux67( ){ readMux67(); if ( mux167 <= 63 ) { digMux167 = false; } if ( mux167 >= 959 ) { digMux167 = true; } if ( mux267 <= 63 ) { digMux267 = false; } if ( mux267 >= 959 ) { digMux267 = true; } if ( mux367 <= 63) { digMux367 = false; } if ( mux367 >= 959 ) { digMux367 = true; } if ( mux467 <= 63 ) { digMux467 = false; } if ( mux467 >= 959 ) { digMux467 = true; } if ( mux567 <= 63 ) { digMux567 = false; } if ( mux567 >= 959 ) { digMux567 = true; } if ( mux667 <= 63 ) { digMux667 = false; } if ( mux667 >= 959 ) { digMux667 = true; } if ( mux767 <= 63 ) { digMux767 = false; } if ( mux767 >= 959 ) { digMux767 = true; } if ( mux867 <= 63 ) { digMux867 = false; } if ( mux867 >= 959 ) { digMux867 = true; } if ( mux967 <= 63 ) { digMux967 = false; } if ( mux967 >= 959 ) { digMux967 = true; } if ( mux1067 <= 63 ) { digMux1067 = false; } if ( mux1067 >= 959 ) { digMux1067 = true; } if ( mux1167 <= 63) { digMux1167 = false; } if ( mux1167 >= 959 ) { digMux1167 = true; } if ( mux1267 <= 63 ) { digMux1267 = false; } if ( mux1267 >= 959 ) { digMux1267 = true; } if ( mux1367 <= 63 ) { digMux1367 = false; } if ( mux1367 >= 959 ) { digMux1367 = true; } if ( mux1467 <= 63 ) { digMux1467 = false; } if ( mux1467 >= 959 ) { digMux1467 = true; } if ( mux1567 <= 63 ) { digMux1567 = false; } if ( mux1567 >= 959 ) { digMux1567 = true; } if ( mux1667 <= 63 ) { digMux1667 = false; } if ( mux1667 >= 959 ) { digMux1667 = true; } }
void printDigMux51( int tx ){ digMux51(); Serial.println( " ___________________ " ); Serial.print( "| " ); Serial.print( digMux151 ); Serial.print( " | " ); Serial.print( digMux251 ); Serial.print( " | " ); Serial.print( digMux351 ); Serial.print( " | " ); Serial.print( digMux451 ); Serial.println( " |" ); Serial.println( " ___________________ " ); Serial.print( "| " ); Serial.print( digMux551 ); Serial.print( " | " ); Serial.print( digMux651 ); Serial.print( " | " ); Serial.print( digMux751 ); Serial.print( " | " ); Serial.print( digMux851 ); Serial.println( " |" ); Serial.print( " ___________________ " ); delay ( tx ); Serial.println( " " ); }
void printDigMuxA67( int tx ){ digMux67(); Serial.println( " ___________________ " ); Serial.print( "| " ); Serial.print( digMux167 ); Serial.print( " | " ); Serial.print( digMux267 ); Serial.print( " | " ); Serial.print( digMux367 ); Serial.print( " | " ); Serial.print( digMux467 ); Serial.println( " |" ); Serial.println( " ___________________ " ); Serial.print( "| " ); Serial.print( digMux567 ); Serial.print( " | " ); Serial.print( digMux667 ); Serial.print( " | " ); Serial.print( digMux767 ); Serial.print( " | " ); Serial.print( digMux867 ); Serial.println( " |" ); Serial.print( " ___________________ " ); delay ( tx ); Serial.println( " " ); }
void printDigMuxB67( int tx ){ digMux67(); Serial.println( " ___________________ " ); Serial.print( "| " ); Serial.print( digMux967 ); Serial.print( " | " ); Serial.print( digMux1067 ); Serial.print( " | " ); Serial.print( digMux1167 ); Serial.print( " | " ); Serial.print( digMux1267 ); Serial.println( " |" ); Serial.println( " ___________________ " ); Serial.print( "| " ); Serial.print( digMux1367 ); Serial.print( " | " ); Serial.print( digMux1467 ); Serial.print( " | " ); Serial.print( digMux1567 ); Serial.print( " | " ); Serial.print( digMux1667 ); Serial.println( " |" ); Serial.print( " ___________________ " ); delay ( tx ); Serial.println( " " ); }
uint8_t muxX51( int channel ){ int x; if( channel == 1 ){ mux51( 0, 0, 0 ); x = analogRead(MUX51); } else if ( channel == 2 ){ mux51( 0, 0, 1 ); x = analogRead(MUX51); } else if ( channel == 3 ){ mux51( 0, 1, 0 ); x = analogRead(MUX51); } else if ( channel == 4 ){ mux51( 0, 1, 1 ); x = analogRead(MUX51); } else if ( channel == 1 ){ mux51( 1, 0, 0 ); x = analogRead(MUX51); } else if ( channel == 1 ){ mux51( 1, 0, 1 ); x = analogRead(MUX51); } else if ( channel == 1 ){ mux51( 1, 1, 0 ); x = analogRead(MUX51); } else if ( channel == 1 ){ mux51( 1, 1, 1 ); x = analogRead(MUX51); } return x; }
uint8_t muxX67( int channel ){ int x; if ( channel == 1 ) { mux67( 0, 0, 0, 0 ); x = analogRead(MUX67); } else if ( channel == 2 ) { mux67( 0, 0, 0, 1 ); x = analogRead(MUX67); } else if ( channel == 3 ) { mux67( 0, 0, 1, 0 ); x = analogRead(MUX67); } else if ( channel == 4 ) { mux67( 0, 0, 1, 1 ); x = analogRead(MUX67); } else if ( channel == 5 ) { mux67( 0, 1, 0, 0 ); x = analogRead(MUX67); } else if ( channel == 6 ) { mux67( 0, 1, 0, 1 ); x = analogRead(MUX67); } else if ( channel == 7 ) { mux67( 0, 1, 1, 0 ); x = analogRead(MUX67); } else if ( channel == 8 ) { mux67( 0, 1, 1, 1 ); x = analogRead(MUX67); } else if ( channel == 9 ) { mux67( 1, 0, 0, 0 ); x = analogRead(MUX67); } else if ( channel == 10 ) { mux67( 1, 0, 0, 1 ); x = analogRead(MUX67); } else if ( channel == 11 ) { mux67( 1, 0, 1, 0 ); x = analogRead(MUX67); } else if ( channel == 12 ) { mux67( 1, 0, 1, 1 ); x = analogRead(MUX67); } else if ( channel == 13 ) { mux67( 1, 1, 0, 0 ); x = analogRead(MUX67); } else if ( channel == 14 ) { mux67( 1, 1, 0, 1 ); x = analogRead(MUX67); } else if ( channel == 15 ) { mux67( 1, 1, 1, 0 ); x = analogRead(MUX67); } else if ( channel == 16 ) { mux67( 1, 1, 1, 1 ); x = analogRead(MUX67); } return x; }
//#endif
int countDigMux51( ) { int x; digMux51( ); x = ( digMux151*( 2^0 ) ) + ( digMux251*( 2^1 ) ) + ( digMux351*( 2^2 ) ) + ( digMux451*( 2^3 ) ) + ( digMux551*( 2^4 ) ) + ( digMux651*( 2^5 ) ) + ( digMux751*( 2^6 ) ) + ( digMux851*( 2^7 ) ) - 1; return x; }
int countDigMux67( ) { int x; digMux67( ); x = ( digMux167*( 2^0 ) ) + ( digMux267*( 2^1 ) ) + ( digMux367*( 2^2 ) ) + ( digMux467*( 2^3 ) ) + ( digMux567*( 2^4 ) ) + ( digMux667*( 2^5 ) ) + ( digMux767*( 2^6 ) ) + ( digMux867*( 2^7 ) ) + ( digMux967*( 2^8 ) ) + ( digMux1067*( 2^9 ) ) + ( digMux1167*( 2^10 ) ) + ( digMux1267*( 2^11 ) ) + ( digMux1367*( 2^12 ) ) + ( digMux1467*( 2^13 ) ) + ( digMux1567*( 2^14 ) ) + ( digMux1667*( 2^15 ) ) -1; return x; }
void setup ( ) {
setMux51(4, 3, 2, 5, 0);
}
void loop ( ) {
int z;
z = countDigMux51();
Serial.println(z);
}