Remarks

SpdtSwitch
Status Status badge: working
Source code GitHub
NuGet package NuGet Gallery for Meadow.Foundation

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

Code Example

protected SpdtSwitch spdtSwitch;

public override Task Initialize()
{
    Console.WriteLine("Initializing...");

    spdtSwitch = new SpdtSwitch(Device.CreateDigitalInputPort(Device.Pins.D15, InterruptMode.EdgeBoth, ResistorMode.InternalPullDown));
    spdtSwitch.Changed += (s, e) =>
    {
        Console.WriteLine(spdtSwitch.IsOn ? "Switch is on" : "Switch is off");
    };

    Console.WriteLine("SpdtSwitch ready...");

    return Task.CompletedTask;
}

Sample project(s) available on GitHub

Wiring Example

<img src="../../API_Assets/Meadow.Foundation.Sensors.Switches.SpdtSwitch/SpdtSwitch_Fritzing.svg"

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(IDigitalInputController, IPin, InterruptMode, ResistorMode)

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(IDigitalInputController device, IPin pin, InterruptMode interruptMode, ResistorMode resistorMode)

Parameters

Type Name Description
IDigitalInputController device
IPin pin
InterruptMode interruptMode
ResistorMode resistorMode

SpdtSwitch(IDigitalInputController, IPin, InterruptMode, ResistorMode, TimeSpan, TimeSpan)

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(IDigitalInputController device, IPin pin, InterruptMode interruptMode, ResistorMode resistorMode, TimeSpan debounceDuration, TimeSpan glitchFilterCycleCount)

Parameters

Type Name Description
IDigitalInputController device
IPin pin
InterruptMode interruptMode
ResistorMode resistorMode
TimeSpan debounceDuration
TimeSpan glitchFilterCycleCount

SpdtSwitch(IDigitalInputPort)

Creates a SpdtSwitch on a especified interrupt port

Declaration
public SpdtSwitch(IDigitalInputPort interruptPort)

Parameters

Type Name Description
IDigitalInputPort interruptPort

Properties

DigitalIn

Returns the DigitalInputPort.

Declaration
protected IDigitalInputPort DigitalIn { get; 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, DigitalPortResult)

Event handler when switch value has been changed

Declaration
protected void DigitalInChanged(object sender, DigitalPortResult e)

Parameters

Type Name Description
System.Object sender
DigitalPortResult e

Events

Changed

Raised when the switch circuit is opened or closed.

Declaration
public event EventHandler Changed

Event Type

Type Description
EventHandler