Meadow.Foundation.Sensors.Switches.DipSwitch
DipSwitch | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
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