Help using MCP23017 & Adafruit-MCP23017-Arduino-Library

Hello all, I recently bought a couple of MCP23017 i2c port expanders from adafruit to drive 16 LEDs for my very first arduino project (a newbie). My inputs are 16 (maybe more) piezo sensors connected to the “mux shield”. When a piezo is struck it sends a midi Note. So each sensor correlates to a specific notes and now I would like to add a LED to each sensor. I had previously tried a pcf8575 breakout board and found it to have a poor design and difficult to use.

Can someone show me how to use the Adafruit-MCP23017-Arduino-Library and http://www.adafruit.com/products/732 MPC23017 to accomplish this.
A perfect example of what I’m trying to do is the midi_footsteps controller, which could be found here: MIDI Footsteps. I’ve got the multiplexers and midiOUT working thanks to Grumpy_mike, Crossroads and others in the Arduino forum. And now the final part is to add the LED section. Can anyone help me get this finale piece in place.

The library:

The data sheet:
http://ww1.microchip.com/downloads/en/devicedoc/21952b.pdf
The wiring:

The sketch goes like this: ( except no muxs are used here, in my actual project I’m using mux-shield i.e. 4051 multiplexers for up to 48 pads and the midi shield for midi OUT ) but you can get the basic idea. It’s like a piano with keys that light up or a drum kit with pads that light up on inpact. So noteON = LED on.

/
// DESCRIPTION:
// Arduino analog input used to sense piezo drum hits then sent serialy to processing.

//*******************************************************************************************************************
// User settable variables
//*******************************************************************************************************************

unsigned char PadNote[6] = {52,16,66,63,40,65}; // MIDI notes from 0 to 127 (Mid C = 60)

int PadCutOff[6] = {600,600,600,600,600,600}; // Minimum Analog value to cause a drum hit

int MaxPlayTime[6] = {90,90,90,90,90,90}; // Cycles before a 2nd hit is allowed

#define midichannel 0; // MIDI channel from 0 to 15 (+1 in “real world”)

boolean VelocityFlag = true; // Velocity ON (true) or OFF (false)

//*******************************************************************************************************************
// Internal Use Variables
//*******************************************************************************************************************

boolean activePad[6] = {0,0,0,0,0,0}; // Array of flags of pad currently playing
int PinPlayTime[6] = {0,0,0,0,0,0}; // Counter since pad started to play

unsigned char status;

int pin = 0;
int hitavg = 0;

//*******************************************************************************************************************
// Setup
//*******************************************************************************************************************

void setup()
{
Serial.begin(57600); // connect to the serial port 115200
}

//*******************************************************************************************************************
// Main Program
//*******************************************************************************************************************

void loop()
{
for(int pin=0; pin < 6; pin++)
{
hitavg = analogRead(pin); // read the input pin

if((hitavg > PadCutOff[pin]))
{
if((activePad[pin] == false))
{
if(VelocityFlag == true)
{
// hitavg = 127 / ((1023 – PadCutOff[pin]) / (hitavg – PadCutOff[pin])); // With full range (Too sensitive ?)
hitavg = (hitavg /  -1 ; // Upper range
}
else
{
hitavg = 127;
}

MIDI_TX(144,PadNote[pin],hitavg);
PinPlayTime[pin] = 0;
activePad[pin] = true;
}
else
{
PinPlayTime[pin] = PinPlayTime[pin] + 1;
}
}
else if((activePad[pin] == true))
{
PinPlayTime[pin] = PinPlayTime[pin] + 1;

if(PinPlayTime[pin] > MaxPlayTime[pin])
{
activePad[pin] = false;
MIDI_TX(128,PadNote[pin],127);
}
}
}
}

//*******************************************************************************************************************
// Transmit MIDI Message
//*******************************************************************************************************************
void MIDI_TX(unsigned char MESSAGE, unsigned char PITCH, unsigned char VELOCITY)
{
status = MESSAGE + midichannel;
Serial.print(status);
Serial.print(PITCH);
Serial.print(VELOCITY);
}


}
}

keyword: bitmasking
Thanks much.

Are you still working on this? If so, I have many questions since I’m going to do something very similar. For example, did you need an amplifier for your piezo elements, or were they sensitive enough. Which ones did you use? I’m doing a DAS system to record the performance someone plays on a musical instrument like a xylophone.