Hello and welcome!
You're thinking about it correctly, and in fact either method would work. That is to say, you could set up an interrupt for each pin like so:
public class Program
{
static InterruptPort pin1 = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
static InterruptPort pin2 = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
static InterruptPort pin3 = new InterruptPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
public static void Main()
{
pin1.OnInterrupt += pin1_OnInterrupt;
pin2.OnInterrupt += pin2_OnInterrupt;
pin3.OnInterrupt += pin3_OnInterrupt;
Thread.Sleep(Timeout.Infinite);
}
static void pin1_OnInterrupt(uint port, uint state, DateTime time)
{
// Do something with pin 1
}
static void pin2_OnInterrupt(uint port, uint state, DateTime time)
{
// Do something with pin 2
}
static void pin3_OnInterrupt(uint port, uint state, DateTime time)
{
// Do something with pin 3
}
}
You'll, of course, want to change the pins, Port.ResistorMode, and Port.InterruptMode to whatever you're using. You'll notice one of the parameters passed to the OnInterrupt method is port, which actually corresponds to the number of the port that triggered the event. So, you could have all the ports trigger to one event like so:
public class Program
{
static InterruptPort pin1 = new InterruptPort(Pins.GPIO_PIN_D0, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
static InterruptPort pin2 = new InterruptPort(Pins.GPIO_PIN_D1, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
static InterruptPort pin3 = new InterruptPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);
public static void Main()
{
pin1.OnInterrupt += pin_OnInterrupt;
pin2.OnInterrupt += pin_OnInterrupt;
pin3.OnInterrupt += pin_OnInterrupt;
Thread.Sleep(Timeout.Infinite);
}
static void pin_OnInterrupt(uint port, uint state, DateTime time)
{
switch (port)
{
case 39:
// Do something with pin 1
break;
case 38:
// Do something with pin 2
break;
case 3:
// Do something with pin 3
break;
}
}
}
Now, you'll notice the port number in the switch statement doesn't match the Pins.GPIO_PIN_## number, this is because it's the actual CPU pin number, i think. You can easily determine which pin will give you what port number by putting a debug statement in the above pin_OnInterrupt event like so:
static void pin_OnInterrupt(uint port, uint state, DateTime time)
{
Debug.Print(port.ToString());
}
Then, you can just trigger each pin and record the proper port number before building your switch statement. You'll probably have to worry about debouncing, depending on your setup. You can find out more about debouncing, and interrupt ports in general and their alternatives, in this thread:
http://forums.netdui...-and-interrupt/
I hope that helps, and good luck!