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

Syntax

public class SpdtSwitch : ISwitch, ISensor

Remarks

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

Examples

The following example shows how to use a SPDT switch:

using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Sensors.Switches;
using Meadow.Hardware;
using System.Threading;

namespace SpdtSwitch_Sample
{
    public class Program
    {
        static IApp _app; 
        public static void Main()
        {
            _app = new App();
        }
    }

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

        public App ()
        {
            _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());
        }
    }
}
Example Circuit

Constructors

View Source

SpdtSwitch(IDigitalInputPort)

Creates a SpdtSwitch on a especified interrupt port

Declaration
public SpdtSwitch(IDigitalInputPort interruptPort)

Parameters

Type Name Description
IDigitalInputPort interruptPort
View Source

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

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