[Help needed!] using Adafruit-MCP23017-Arduino-Library

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
pitchoilcan
 
Posts: 23
Joined: Tue Apr 24, 2012 10:18 am

Bits and pieces | All together now

Post by pitchoilcan »

http://blog.georgmill.de/2011/03/22/e-d ... st-gebaut/
http://sourceforge.net/projects/yaamidrum/
Thanks
I think it's because of the way the piezo give you a quick reading and then falls rapidly. However in your rewrite they stay on not flicker.

Grummpy Mike from the other forum did the same thing using mcp23016 and foam sensors,
http://www.thebox.myzen.co.uk/Hardware/ ... steps.html
====
http://todbot.com/blog/2006/10/29/spook ... l-arduino/
http://spikenzielabs.com/SpikenzieLabs/DrumKitKit.html
Knock Knock!
// deal with first piezo, this is kind of a hack
val = analogRead(piezoAPin);
if( val >= PIEZOTHRESHOLD ) {
t=0;
while(analogRead(piezoAPin) >= PIEZOTHRESHOLD/2) {
t++;
}
Last edited by pitchoilcan on Tue May 22, 2012 3:37 pm, edited 4 times in total.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: [Help needed!] using Adafruit-MCP23017-Arduino-Library

Post by adafruit_support_rick »

However in you rewrite they stay on not flicker.
Right. That's because your PadPlayTime code doesn't work, and so your loop will turn them on and never turn them off

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: [Help needed!] using Adafruit-MCP23017-Arduino-Library

Post by adafruit_support_rick »

When you edited checkSensors() to get rid of the HiHat stuff, I think you messed up a few else clauses.

Try this:

Code: Select all

void checkSensors(int analogPin)
{

	for(int pin=0; pin < 16; pin++)
	{	
		if(analogPin==0)
		{
			hitavg = mux0array[pin];
			pad=pin;
		}
		if(analogPin==1)
		{
			hitavg = mux1array[pin];
			pad=pin+16;
		}
		if(analogPin==2)
		{
			hitavg = mux2array[pin];
			pad=pin+32;
		}

		if((hitavg > PadCutOff[pin]))
		{
			//Serial.writeln("hitavg > PadCutOff[pin])");
			if((activePad[pad] == false))
			{
				if(VelocityFlag == true)
				{
					  //hitavg = 127 / ((1023 - PadCutOff[pin]) / (hitavg - PadCutOff[pin]));    // With full range (Too sensitive ?)
					  hitavg = (hitavg / 8) -1 ;                                                 // Upper range
				}
				else
				{
					hitavg = 127;
				}
				
				MIDI_TX(144,PadNote[pad],hitavg); 
				PinPlayTime[pad] = 0;
				activePad[pad] = true;
			}
			else
			{
				PinPlayTime[pad] = PinPlayTime[pad] + 1;
			}			
		}
		else 
		{
			if((activePad[pad] == true))
			{
				PinPlayTime[pad] = PinPlayTime[pad] + 1;

				if(PinPlayTime[pad] > MaxPlayTime[pad])
				{
					activePad[pad] = false;
					MIDI_TX(128,PadNote[pad],127); 
				}
			}
		}
				
		if(analogPin==0)
		{
			if (activePad[pad])
				mcp0.digitalWrite(pad, HIGH);
			else
				mcp0.digitalWrite(pad, LOW);
		}
		if(analogPin==1)
		{
//			if (activePad[pad])
//				mcp1.digitalWrite(pad-16, HIGH);
//			else
//				mcp1.digitalWrite(pad-16, LOW);
		}
		if(analogPin==2)
		{
//			if (activePad[pad])
//				mcp2.digitalWrite(pad-32, HIGH);
//			else
//				mcp2.digitalWrite(pad-32, LOW);
		}
	}
}

pitchoilcan
 
Posts: 23
Joined: Tue Apr 24, 2012 10:18 am

Re: [Help needed!] using Adafruit-MCP23017-Arduino-Library

Post by pitchoilcan »

Yes that works ! wow :D I'll take a closer look later today (need to go out and bang on the ole can for a while). but in the mean time. Thanks again!

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: [Help needed!] using Adafruit-MCP23017-Arduino-Library

Post by adafruit_support_rick »

You're welcome! Glad to hear it's working for you! :D

When you're ready to add the other two MCP23017's, wire one of them with pin 15 to +5V and pins 16 & 17 to Gnd (that will be mcp1). Wire another with pin 16 to +5V and pins 15 & 17 to Gnd (that will be mcp2). Then uncomment all the lines that refer to mcp1 and mcp2.

And don't forget to set aside a copy of your working sketch before you start making changes to it!

pitchoilcan
 
Posts: 23
Joined: Tue Apr 24, 2012 10:18 am

Re: [Help needed!] using Adafruit-MCP23017-Arduino-Library

Post by pitchoilcan »

I've found that Pin 18 the reset pin must connected to +5V in order for it to work.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”