Remarks

SpdtSwitch
Status
Source code GitHub
NuGet package

SpdtSwitch represents a simple, two position, Single-Pole-Dual-Throw (SPDT) switch that closes a circuit to either ground/common or high depending on position.

The following example shows how to use a SPDT switch:

public class MeadowApp : App<F7Micro, MeadowApp>
{
    DigitalOutputPort _blueLED;
    SpdtSwitch _spdtSwitch;

    public MeadowApp()
    {
        _blueLED = new DigitalOutputPort(Device.Pins.OnboardLEDBlue, true);

        _spdtSwitch = new SpdtSwitch(Device.Pins.D13);
        _spdtSwitch.Changed += (s, e) =>
        {
            Console.WriteLine("Switch Changed");
            Console.WriteLine("Switch on: " + _spdtSwitch.IsOn.ToString());
        };

        Console.WriteLine("Initial switch state, isOn: " + _spdtSwitch.IsOn.ToString());
    }
}

Sample projects available on GitHub

Wiring Example

Characteristic Locus
Inheritance System.Object > SpdtSwitch
Implements ISensor
Namespace Meadow.Foundation.Sensors.Switches
Assembly Meadow.Foundation.dll

Syntax

public class SpdtSwitch : ISwitch, ISensor

Constructors

SpdtSwitch(IDigitalInputPort)

Creates a SpdtSwitch on a especified interrupt port

Declaration
public SpdtSwitch(IDigitalInputPort interruptPort)

Parameters

Type Name Description
IDigitalInputPort interruptPort

SpdtSwitch(IIODevice, IPin, InterruptMode, ResistorMode, Int32, Int32)

Instantiates a new SpdtSwitch object with the center pin connected to the specified digital pin, one pin connected to common/ground and one pin connected to high/3.3V.

Declaration
public SpdtSwitch(IIODevice device, IPin pin, InterruptMode interruptMode, ResistorMode resistorMode, int debounceDuration = 20, int glitchFilterCycleCount = 0)

Parameters

Type Name Description
IIODevice device
IPin pin
InterruptMode interruptMode
ResistorMode resistorMode
System.Int32 debounceDuration
System.Int32 glitchFilterCycleCount

Properties

DigitalIn

Returns the DigitalInputPort.

Declaration
public IDigitalInputPort DigitalIn { get; protected set; }

Property Value

Type Description
IDigitalInputPort

IsOn

Describes whether or not the switch circuit is closed/connected (IsOn = true), or open (IsOn = false).

Declaration
public bool IsOn { get; protected set; }

Property Value

Type Description
System.Boolean

Methods

DigitalInChanged(Object, DigitalInputPortEventArgs)

Event handler when switch value has been changed

Declaration
protected void DigitalInChanged(object sender, DigitalInputPortEventArgs e)

Parameters

Type Name Description
System.Object sender
DigitalInputPortEventArgs e

Events

Changed

Raised when the switch circuit is opened or closed.

Declaration
public event EventHandler Changed

Event Type

Type Description
System.EventHandler