Hi all,
I am tring to cascade two cd4051s inorder to 16 buttons.
Wiring is done based on http://www.567.dk/arduino/arduinocd4051b02.png this diagram and buttons have 220ohm resistors on readpins.
The problem is I can only read from one 4051 that is connected to Analog 0, the second 4051 does not respond. If I connect the non responding 4051 to A0 it starts working, so I am pretty sure the it is wired correctly.
I checked http://forum.arduino.cc/index.php/topic,21547.0.html this atticle and my others... modified my code, rewired everything, etc... but still no luck.
Most probably I am missing something basic but I am stucked and really appreciate some help.
My code:
int b0 = 0;
int b1 = 0;
int b2 = 0;
const int mux1 = A0;
const int mux2 = A1;
int buttonValue[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int lastButtonValue[16] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
const int ledPin = 13;
void setup(){
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(ledPin, OUTPUT);
}
void loop () {
for (int buttonCount = 0; buttonCount < 8; buttonCount++) {
b0 = bitRead(buttonCount,0);
b1 = bitRead(buttonCount,1);
b2 = bitRead(buttonCount,2);
digitalWrite(4,b0);
digitalWrite(3,b1);
digitalWrite(2,b2);
buttonValue[buttonCount] = digitalRead(mux1);
buttonValue[buttonCount + 8] = digitalRead(mux2);
if(buttonValue[buttonCount] == LOW && lastButtonValue[buttonCount] == HIGH) {
digitalWrite(ledPin, HIGH);
}
if(buttonValue[buttonCount] == HIGH && lastButtonValue[buttonCount] == LOW) {
digitalWrite(ledPin, LOW);
}
lastButtonValue[buttonCount] = buttonValue[buttonCount];
}
}
Many thanks in advance!
Deniz