Arduino > Mutliplexeur d'entrées analogiques 74XX4051
Contents (hide)
/* By : Thomas Ouellet Fredericks Last Modified : 2014/09/30 Outputs over serial (baud 57600) a 74XX4051 analog multiplexer connected to digital pins 2,3,4 and analog pin 0 */ // 74XX4051 ADDRESS PINS : #define S0 2 #define S1 3 #define S2 4 // 74XX4051 ANALOG PIN : #define Z 0 void setup(){ // CONFIGURE ADDRESS PINS pinMode(S0, OUTPUT); pinMode(S1, OUTPUT); pinMode(S2, OUTPUT); // CONFIGURE SERIAL Serial.begin(57600); } void loop () { // LOOP THROUGH ALL THE ADDRESSES for ( byte count = 0; count < 8 ; count++ ) { // SET THE ADDRESS digitalWrite(S0, bitRead(count, 0) ); digitalWrite(S1, bitRead(count, 1) ); digitalWrite(S2, bitRead(count, 2) ); // READ THE ANALOG FOR THAT ADDRESS int reading = analogRead(Z); // SERIAL OUTPUT // print something like : A0-### value Serial.print("A0-"); Serial.print(bitRead(count, 2)); Serial.print(bitRead(count, 1)); Serial.print(bitRead(count, 0)); Serial.print(' '); Serial.println(reading); // 100 ms delay to not stress the serial communication. delay(100); } }