Skip to main content

Meadow.Foundation.Sensors.Switches.DipSwitch

DipSwitch
StatusStatus badge: working
Source codeGitHub
NuGet packageNuGet Gallery for Meadow.Foundation

DipSwitch represents a DIP-switch wired in a bus configuration, in which all switches are terminated to the same ground/common or high pin.

public class MeadowApp : App<F7Micro, MeadowApp>
{
protected DipSwitch dipSwitch;

public MeadowApp()
{
Console.WriteLine("Initializing...");

IDigitalInputPort[] ports =
{
Device.CreateDigitalInputPort(Device.Pins.D06, InterruptMode.EdgeRising, ResistorMode.InternalPullDown),
Device.CreateDigitalInputPort(Device.Pins.D07, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown),
Device.CreateDigitalInputPort(Device.Pins.D08, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown),
Device.CreateDigitalInputPort(Device.Pins.D09, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown),
Device.CreateDigitalInputPort(Device.Pins.D10, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown),
Device.CreateDigitalInputPort(Device.Pins.D11, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown),
Device.CreateDigitalInputPort(Device.Pins.D12, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown),
Device.CreateDigitalInputPort(Device.Pins.D13, InterruptMode.EdgeFalling, ResistorMode.InternalPullDown),
};

dipSwitch = new DipSwitch(ports);
dipSwitch.Changed += (s,e) =>
{
Console.WriteLine("Switch " + e.ItemIndex + " changed to " + (((ISwitch)e.Item).IsOn ? "on" : "off"));
};

Console.WriteLine("DipSwitch...");
}
}

Sample projects available on GitHub

Code Example

protected DipSwitch dipSwitch;

public override Task Initialize()
{
Resolver.Log.Info("Initializing...");

IDigitalInterruptPort[] ports =
{
Device.CreateDigitalInterruptPort(Device.Pins.D06, InterruptMode.EdgeRising, ResistorMode.InternalPullDown),
};

dipSwitch = new DipSwitch(ports);
dipSwitch.Changed += (s, e) =>
{
Resolver.Log.Info("Switch " + e.ItemIndex + " changed to " + (((ISwitch)e.Item).IsOn ? "on" : "off"));
};

Resolver.Log.Info("DipSwitch...");

return Task.CompletedTask;
}

Sample project(s) available on GitHub

Wiring Example

Class DipSwitch

Represents a DIP-switch wired in a bus configuration, in which all switches are terminated to the same ground/common or high pin.

Assembly: Meadow.Foundation.dll
View Source
Declaration
public class DipSwitch

Properties

this[int]

Returns the ISwitch at the specified index.

View Source
Declaration
public ISwitch this[int i] { get; }

Switches

Returns the switch array.

View Source
Declaration
public ISwitch[] Switches { get; }

Methods

HandleSwitchChanged(int)

Event handler when switch value has been changed

View Source
Declaration
protected void HandleSwitchChanged(int switchNumber)
Parameters
TypeName
System.Int32switchNumber

Events

Changed

Raised when one of the switches is switched on or off.

View Source
Declaration
public event ArrayEventHandler Changed
Event Type

Meadow.Foundation.ArrayEventHandler