Thanks all,
I've been thinking about cheater's option, and below is my attempt to read four pins after an interrupt to see which one was the trigger. I can't test this until Monday, so I'll be entertained by your predictions, and I welcome pointers of any kind. (insert pointer joke here) I'll look into a IO expander when it turns out this doesn't work!
A bit more about my project: I'm trying to do a 4 channel version of an earlier project called "clapboard" which depended on 2 interrupts to find the time difference between the arrival of a sound impulse at 2 contact mics attached to a table. That gives me one dimension of position data I can use to control a sound process in Pd. It works (sort of) and you can find out all about it on this webpage:
http://homepage.mac.com/coldham/klang/clapboard.html Anyway, it would be cool to get it working in 2d, so I can use the whole table! Thanks for sharing!
Collin
#include <SimpleMessageSystem.h>
/* clapboard
* ---------------
*
* This version tries to read 4 piezos sharing one interrupt
* each circuit terminates at digital pin 2 (INTO) and one each at
* digital pins 8, 9, 10, &11 (PB0-3)
*
* (copyleft) 2007 by Collin Oldham
* <http://ccrma.stanford.edu/~coldham>
* coldham (at) mac.com
*
*/
#define MAXCOUNT 4500
int clock[0xF]; //that's 15
char i=0;
char pins=0;
void setup(void) {
pinMode(8,INPUT);
pinMode(9,INPUT);
pinMode(10,INPUT);
pinMode(11,INPUT);
Serial.begin(115200);
attachInterrupt(0, hit, RISING);
TCCR1A=0x0; // reset timer 1 (the sixteen bit counter) to it's default mode
TCCR1B=0x2; //set the timer to increment once every 256 clock cycles
}
void loop(void) {
if (TCNT1>MAXCOUNT){ //reset everything when the clock gets higher than it should need to.
pins=0;
for(i=0;i<0xF;i++){
clock[i] = 0;
}
}
if (pins==0xF) { //all four pins are hit, so send the time tags.
cli(); //disable interrupts
for(i=0;i<0xF;i++){
if(clock[i] != 0){
messageSendChar(i);
messageSendInt(clock[i]);
messageEnd();
clock[i] = 0;
}
}
delay(70);
pins=0;
sei(); //enable interrupts
}
}
void hit()
{
pins |= PINB & 0x0f; // I just want to read the fist 4 pins of port b, and I "|=" them into "pins" so I don't overwrite previous hits with a zero. PINB reprsents the values read on port b.
if(pins==1||2||4||8){ // If only one bit is high, this is the first hit, so reset the clock.
TCNT1=0;
}
clock[pins]=TCNT1;
}