namespace NetduinoPlusApplication1 { public class Program { // initialize the onboard LED private static OutputPort LEDDisplay = new OutputPort(Pins.GPIO_PIN_D1, false); private static InterruptPort switchPort = new InterruptPort(Pins.GPIO_PIN_D2, false, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); private static InterruptPort switchPort2 = new InterruptPort(Pins.GPIO_PIN_D3, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth); public static void Main() { // initialize the onboard switch // add an event-handler for the switch switchPort.OnInterrupt += new NativeEventHandler(switchPort_OnInterrupt); switchPort2.OnInterrupt += new NativeEventHandler(switchPort2_OnInterrupt); Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableDhcp(); WebServer webServer = new WebServer(); webServer.ListenForRequest(); } /// /// Event handler for the onboard switch. /// ///The port for which the event occurs. ///The state of the switch. ///Time of the event. private static void switchPort_OnInterrupt(uint port, uint data, DateTime time) { // turn the LED on, if the button is pressed (== 0, because switch is inverted) Debug.Print("Port: " + port.ToString() + " State: " + data.ToString()); Thread.Sleep(1500); switchPort.ClearInterrupt(); } private static void switchPort2_OnInterrupt(uint port, uint data, DateTime time) { // turn the LED on, if the button is pressed (== 0, because switch is inverted) Debug.Print("Port2: " + port.ToString() + " State2: " + data.ToString()); Thread.Sleep(3000); switchPort2.ClearInterrupt(); } } }
How to Handle Multiple Interrupts
#1
Posted 30 May 2012 - 05:28 PM
#2
Posted 31 May 2012 - 09:29 AM
#3
Posted 05 June 2012 - 01:25 PM
From your code comments it seems the buttons are switched to ground - do you have pull-up resistors connected (so the port is in defined state when the button is not switched on)? If not, I would try using ResistorMode.PullUp to enable Netduino's internal pull-up resistors. Also, you may consider adding a capacitor connected between the switch contacts to reduce bouncing (tens to hundreds of nF are commonly used, the exact value depends on the button bouncing characteristics).
It should not be necessary to call ClearInterrupt(), this method is intended for level interrupts, not edge.
I changed my resistormode to pullup as you suggested and my interrupts do not trigger at all now. I've tried triggering them with the 5V jumper from the Netduino itself. It seems something is stopping my interrupts from triggering correctly.
#4
Posted 05 June 2012 - 01:33 PM
#5
Posted 05 June 2012 - 01:39 PM
#6
Posted 05 June 2012 - 02:13 PM
When pull-up resistors are used you need to connect the pin to ground to trigger the interrupt.
i wish to trigger my interrupt on high voltages(aka 5 volts) though. is there a way to do such?
#7
Posted 05 June 2012 - 02:23 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users