analog multiplexer/demultiplexer------------------4051
A multiplexer or demultiplexer enables you to expand the in-and outputs on your Arduino board. The 4051 is an 8 channel analog multiplexer / demultiplexer, thus:
- If you use the 4051 as a Multiplexer: You can choose between 8 different inputs and select just one you want to read at the time.
- If you use the 4051 as a Demultiplexer you can choose between 8 different outputs and select just one you want to write at the time.
- If S0 and S1 are HIGH and S2 is LOW pin y3 is selected (1+2+0 = 3).
- If S0 and S2 is HIGH and S1 LOW pin y5 is selected (1+0+4 = 5).
- Z ----- common input/output (connected to Arduino Input/Output)
- E ----- enable input (active LOW) (connected to ground (gnd))
- Vee --- negative supply voltage (connected to ground (gnd))
- gnd --- ground (0 V)
- S0-S2 - select inputs (connected to three arduino digitalOut Pins)
- y0-y7 - independent inputs/outputs
- Vcc --- positive supply voltage (5v)
//////////////////////////////////////////////////////////////////////code example
/* * codeexample for useing a 4051 * analog multiplexer / demultiplexer * by david c. and tomek n.* for k3 / malm� h�gskola * */ int led = 13; //just a led int r0 = 0; //value select pin at the 4051 (s0) int r1 = 0; //value select pin at the 4051 (s1) int r2 = 0; //value select pin at the 4051 (s2) int row = 0; // storeing the bin code int count = 0; // just a count int bin [] = {000, 1, 10, 11, 100, 101, 110, 111};//bin = bin�r, some times it is so easy void setup(){ pinMode(2, OUTPUT); // s0 pinMode(3, OUTPUT); // s1 pinMode(4, OUTPUT); // s2 digitalWrite(led, HIGH); beginSerial(9600); } void loop () { for (count=0; count<=7; count++) { row = bin[count]; r0 = row & 0x01; r1 = (row>>1) & 0x01; r2 = (row>>2) & 0x01; digitalWrite(2, r0); digitalWrite(3, r1); digitalWrite(4, r2); //Serial.println(bin[count]); delay (1000); } }
No comments:
Post a Comment