help with a 4051 projct

hi all,

im hoping if someone here might be able to help here.

so i want to use a 4051 or 2 to get 12 analogue inputs as well as a couple of buttons for a midi controller.

reason for this is that i only have a nano to hand atm and need to expand the i/o.

if anyone can help with hook up and code or any, it would be great

kind regards


Connections may be like this
You will find some code in this forum as well.

// read analog data from 2*8 inputs at 2*4051
// store in tbl1

const byte p0=10,p1=11,p2=12;
int tbl1[16];

void setup()
  pinMode(p0,OUTPUT); // output address pins for 4051

void readall()
  byte i; // temporary variable for counting
  for (i=0; i<=7; i++)
  // set up address to
    digitalWrite(p0, i&1);
    digitalWrite(p1, i&2);
    digitalWrite(p2, i&4);
  // then read the analog value at 4051s pin i
  tbl1[i]=analogRead(0); // the 4051s Y-line connected to A0
  tbl1[i+8]=analogRead(1); // the 4051s Y-line connected to A1

void loop()
  readall(); // get 16 inputs stored to tbl1
  // do computing..