Toolbox.NETMF.Hardware.RotaryDIPSwitch


Toolbox.NETMF.Hardware.RotaryDIPSwitch(Pins)
  • Pins The pins referring to the switch's binary outputs

Methods

  • Read() Returns the current value

Events

  • OnInterrupt(Unused, State, Time) When the state changed, this event is triggered.

How to connect

Toolbox.NETMF.Hardware.RotaryDIPSwitch.png

Sample code in C#

public class Program
{
    public static void Main()
    {
        // The switch is connected to pins 1, 2, 4 and 8, so a 4-bit switch (define them in the correct sequence)
        Cpu.Pin[] RotaryPins = { Pins.GPIO_PIN_D1, Pins.GPIO_PIN_D2, Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D8 };
        RotaryDIPSwitch Switch = new RotaryDIPSwitch(RotaryPins);
        Switch.OnInterrupt += new NativeEventHandler(Switch_OnInterrupt);

        // Let the events do the rest
        Thread.Sleep(Timeout.Infinite);
    }

    /// <summary>
    /// The switch' state is changed
    /// </summary>
    /// <param name="Unused">Unused</param>
    /// <param name="State">New state</param>
    /// <param name="Time">Time of the event</param>
    static void Switch_OnInterrupt(uint Unused, uint State, DateTime Time)
    {
        Debug.Print(State.ToString());
    }
}

Sample code in VB

Module Module1
    Public WithEvents Switch As RotaryDIPSwitch

    Sub Main()
        ' The switch is connected to pins 1, 2, 4 and 8, so a 4-bit switch (define them in the correct sequence)
        Dim RotaryPins(0 To 3) As Cpu.Pin
        RotaryPins(0) = Pins.GPIO_PIN_D1
        RotaryPins(1) = Pins.GPIO_PIN_D2
        RotaryPins(2) = Pins.GPIO_PIN_D4
        RotaryPins(3) = Pins.GPIO_PIN_D8
        Switch = New RotaryDIPSwitch(RotaryPins)

        ' Let the events do the rest
        Thread.Sleep(Timeout.Infinite)
    End Sub

    ''' <summary>
    ''' The switch' state is changed
    ''' </summary>
    ''' <param name="Unused">Unused</param>
    ''' <param name="State">New state</param>
    ''' <param name="Time">Time of the event</param>
    Private Sub Switch_OnInterrupt(Unused As UInteger, State As UInteger, Time As Date) Handles Switch.OnInterrupt
        Debug.Print(State.ToString())
    End Sub
End Module

Related documents

Last edited Jan 1, 2013 at 9:17 PM by Garrcomm, version 3