~All,
I'm fairly new at Arduino / and am trying to learn by doing. My current project is -- I am trying to build an application that reads about 20+ digital buttons. I thought I would try to get a 4051 Mux/ Demux setup working with a series of 74HCT4051N's to experiment with.
My objective is to fully understand how to read (4) four momentary switches (and identify them from each other) and armed with that I can expand on my own.
I am struggling with getting the basic understanding. I have built the attached circuit.
Trying to learn from examples below -- but they are confusing me quite a bit.
http://playground.arduino.cc/learning/4051
http://tomekness.files.wordpress.com/2007/02/analog_multiplexer_demultiplexer_4051.pdf
They are confusing me a good deal.
I understand that the muiltplexer / demux setup sequerntially runs throught the switches is suppose to reads the value for each button. I haven't got that to work for me.
Any pointers to get me headed in the right direction would be super apprecaited.
- 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);
}
}
4051_test.fzz (15.9 KB)