Meadow.Foundation.Sensors.Switches.SpdtSwitch
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
Code Example
protected SpdtSwitch spdtSwitch;
public override Task Initialize()
{
Resolver.Log.Info("Initializing...");
spdtSwitch = new SpdtSwitch(Device.CreateDigitalInterruptPort(Device.Pins.D15, InterruptMode.EdgeBoth, ResistorMode.InternalPullDown));
spdtSwitch.Changed += (s, e) =>
{
Resolver.Log.Info(spdtSwitch.IsOn ? "Switch is on" : "Switch is off");
};
Resolver.Log.Info("SpdtSwitch ready...");
return Task.CompletedTask;
}
Sample project(s) available on GitHub