Remarks

SpstSwitch
Status
Source code GitHub
NuGet package

SpstSwitch represents a simple, on/off, Single-Pole-Single-Throw (SPST) switch that closes a circuit to either ground/common or high:

Use the CircuitTerminationType to specify whether the other side of the switch terminates to ground or high.

The following example shows how to use a SPST switch:

public class MeadowApp : App<F7Micro, MeadowApp>
{
    DigitalOutputPort _blueLED;
    SpstSwitch _spstSwitch;

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

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

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

Sample projects available on GitHub

Wiring Example

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

Syntax

public class SpstSwitch : ISwitch, ISensor

Constructors

View Source

SpstSwitch(IDigitalInputPort)

Creates a SpstSwitch on a especified interrupt port

Declaration
public SpstSwitch(IDigitalInputPort interruptPort)

Parameters

Type Name Description
IDigitalInputPort interruptPort
View Source

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

Instantiates a new SpstSwitch object connected to the specified digital pin, and with the specified CircuitTerminationType in the type parameter.

Declaration
public SpstSwitch(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

View Source

DigitalIn

Returns the DigitalInputPort.

Declaration
public IDigitalInputPort DigitalIn { get; protected set; }

Property Value

Type Description
IDigitalInputPort
View Source

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

View Source

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

View Source

Changed

Raised when the switch circuit is opened or closed.

Declaration
public event EventHandler Changed

Event Type

Type Description
System.EventHandler