Sure, here is test code I was playing with:
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;
namespace SwitchDemo
{
public class Program
{
// take care of initializing relay that is connected...
OutputPort r0 = new OutputPort(Pins.GPIO_PIN_D0, true);
OutputPort r1 = new OutputPort(Pins.GPIO_PIN_D1, true);
OutputPort r2 = new OutputPort(Pins.GPIO_PIN_D2, true);
OutputPort r3 = new OutputPort(Pins.GPIO_PIN_D3, true);
OutputPort r4 = new OutputPort(Pins.GPIO_PIN_D4, true);
OutputPort r5 = new OutputPort(Pins.GPIO_PIN_D5, true);
OutputPort r6 = new OutputPort(Pins.GPIO_PIN_D6, true);
OutputPort r7 = new OutputPort(Pins.GPIO_PIN_D7, true);
static InterruptPort sensorTop = new InterruptPort(Pins.GPIO_PIN_D8, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
static InterruptPort sensorBottom = new InterruptPort(Pins.GPIO_PIN_D11, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
static InterruptPort switchUp = new InterruptPort(Pins.GPIO_PIN_D12, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
static InterruptPort switchDown = new InterruptPort(Pins.GPIO_PIN_D13, true, Port.ResistorMode.Disabled, Port.InterruptMode.InterruptEdgeBoth);
public static void Main()
{
sensorTop.OnInterrupt += new NativeEventHandler(test_events);
sensorBottom.OnInterrupt += new NativeEventHandler(test_events);
switchUp.OnInterrupt += new NativeEventHandler(test_events);
switchDown.OnInterrupt += new NativeEventHandler(test_events);
Thread.Sleep(Timeout.Infinite);
}
private static void test_events(uint data1, uint data2, DateTime time)
{
// Debug.Print("data1=" + data1.ToString() + ", data2=" + data2.ToString() + ", time=" + time.Ticks.ToString());
if (data1 == (uint)sensorTop.Id)
{
sensorTop.DisableInterrupt();
Debug.Print("sensorTop::value=" + data2.ToString());
sensorTop.EnableInterrupt();
}
else if (data1 == (uint)sensorBottom.Id)
{
sensorBottom.DisableInterrupt();
Debug.Print("sensorBottom::value=" + data2.ToString());
sensorBottom.EnableInterrupt();
}
else if (data1 == (uint)switchUp.Id)
{
switchUp.DisableInterrupt();
Debug.Print("switchUp::value=" + data2.ToString());
switchUp.EnableInterrupt();
}
else if (data1 == (uint)switchDown.Id)
{
switchDown.DisableInterrupt();
Debug.Print("switchDown::value=" + data2.ToString());
switchDown.EnableInterrupt();
}
}
}
}
With a the reed switch (top sensor) when closing the circuit we get this:
sensorTop::value=1
sensorTop::value=0
sensorTop::value=1
sensorTop::value=0
sensorTop::value=1
When I open the circuit (pull magnet away) I get this.
sensorTop::value=0
So bouncing at the start...
But when I flip the toggle switch UP (switchUp) I get this:
switchDown::value=0
switchUp::value=1
switchUp::value=0
switchDown::value=0
switchUp::value=0
switchUp::value=0
switchDown::value=0
switchUp::value=0
switchUp::value=0
switchDown::value=0
switchUp::value=1
switchUp::value=0
When I let it return to home (off) I get this:
switchUp::value=0
Maybe I need to switch to a pull up resistor configuration with a capacitor for denouncing?
Thanks guys