I am new to both C# and the micro framework. In the process of using the beginners guide and trying to learn the micro framework I came across the section on interrupts and now I am completely lost! the code from the beginners guide is as follows:
static OutputPort LED;
public static void Main()
{
LED = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.LED, true);
// the pin will generate interrupt on high and low edges
InterruptPort IntButton = new InterruptPort((Cpu.Pin)FEZ_Pin.Interrupt.LDR, true,
Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeBoth);
// add an interrupt handler to the pin
IntButton.OnInterrupt += new NativeEventHandler(IntButton_OnInterrupt);
//do anything you like here
Thread.Sleep(Timeout.Infinite);
}
static void IntButton_OnInterrupt(uint port, uint state,DateTime time)
{
// set LED to the switch state
LED.Write(state == 0);
}
1st question:
Where do the values passed to the IntButton_OnInterrupt function come from and how can I change what is passed to the function? ( I want to make an interrupt act as a switch. i.e. press once to turn on and press again to turn off.)
2nd question:
If state is passed to the function why do we have to set it to ‘0’?