Just use this digitalReadMux() in place of digitalRead() for your buttons.
const int select[] = {8,9,10}; // array of the pins connected to the 4051 input select lines
const int analogPin = A1; // the analog pin connected to the multiplexer output
boolean digitalReadMux(int channel)
{
// the following sets the selector pins HIGH and LOW to match the binary value of channel
for(int bit = 0; bit < 3; bit++)
{
int pin = select[bit]; // the pin wired to the multiplexer select bit
int isBitSet = bitRead(channel, bit); // true if given bit set in channel
digitalWrite(pin, isBitSet);
}
pinMode(analogPin, INPUT)
return digitalRead(analogPin);
}
// this function returns the analog value for the given channel
int analogReadMux( int channel)
{
// the following sets the selector pins HIGH and LOW to match the binary value of channel
for(int bit = 0; bit < 3; bit++)
{
int pin = select[bit]; // the pin wired to the multiplexer select bit
int isBitSet = bitRead(channel, bit); // true if given bit set in channel
digitalWrite(pin, isBitSet);
}
return analogRead(analogPin);
}