Remarks

DipSwitch
Status
Source code GitHub
NuGet package

DipSwitch represents a DIP-switch wired in a bus configuration, in which all switches are terminated to the same ground/common or high pin.

public class MeadowApp : App<F7Micro, MeadowApp>
{
    public void App()
    {
        var dipSwitch = new DipSwitch(IDigitalPin[] {
            Device.Pins.D05, Device.Pins.D06, 
            Device.Pins.D07, Device.Pins.D08, 
            Device.Pins.D09, Device.Pins.D10, 
            Device.Pins.D11, Device.Pins.D12,  },
            CircuitTerminationType.CommonGround);

        dipSwitch.Changed += (object s, ArrayEventArgs e) =>
        {
            Debug.Print("Switch " + e.ItemIndex + " changed to " 
                + (((ISwitch)e.Item).IsOn ? "on" : "off"));
        };

        Thread.Sleep(Timeout.Infinite);
    }
}

Sample projects available on GitHub

Wiring Example

Characteristic Locus
Inheritance System.Object > DipSwitch
Inherited Members System.Object.ToString() System.Object.Equals(System.Object) System.Object.Equals(System.Object, System.Object) System.Object.ReferenceEquals(System.Object, System.Object) System.Object.GetHashCode() System.Object.GetType() System.Object.MemberwiseClone()
Namespace Meadow.Foundation.Sensors.Switches
Assembly Meadow.Foundation.dll

Syntax

public class DipSwitch

Constructors

DipSwitch(IDigitalInputPort[])

Creates a new DipSwitch connected to an array of Interrupt Ports

Declaration
public DipSwitch(IDigitalInputPort[] interruptPorts)

Parameters

Type Name Description
IDigitalInputPort[] interruptPorts

DipSwitch(IIODevice, IPin[], InterruptMode, ResistorMode, Int32, Int32)

Creates a new DipSwitch connected to the specified switchPins, with the InterruptMode and ResisterMode specified by the type parameters.

Declaration
public DipSwitch(IIODevice device, IPin[] switchPins, InterruptMode interruptMode, ResistorMode resistorMode, int debounceDuration = 20, int glitchFilterCycleCount = 0)

Parameters

Type Name Description
IIODevice device
IPin[] switchPins
InterruptMode interruptMode
ResistorMode resistorMode
System.Int32 debounceDuration
System.Int32 glitchFilterCycleCount

Fields

Switches

Returns the switch array.

Declaration
public ISwitch[] Switches

Field Value

Type Description
ISwitch[]

Properties

Item[Int32]

Returns the ISwitch at the specified index.

Declaration
public ISwitch this[int i] { get; }

Parameters

Type Name Description
System.Int32 i

Property Value

Type Description
ISwitch

Methods

HandleSwitchChanged(Int32)

Event handler when switch value has been changed

Declaration
protected void HandleSwitchChanged(int switchNumber)

Parameters

Type Name Description
System.Int32 switchNumber

Events

Changed

Raised when one of the switches is switched on or off.

Declaration
public event ArrayEventHandler Changed

Event Type

Type Description
ArrayEventHandler