Skip to main content

Meadow.Foundation.ICs.DigiPots.Mcp4162

Mcp4162
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.ICs.DigiPots.Mcp4xxx

Code Example

protected Mcp4162 mcp;

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

mcp = new Mcp4162(
Device.CreateSpiBus(),
Device.Pins.D15.CreateDigitalOutputPort(),
new Resistance(5, Resistance.UnitType.Kiloohms)
);

return base.Initialize();
}

public override async Task Run()
{
Resolver.Log.Info("Run");

for (var i = 0; i <= mcp.MaxResistance.Ohms; i += 100)
{
var r = new Resistance(i, Resistance.UnitType.Ohms);
Resolver.Log.Info($"Setting resistance to {r.Ohms:0} ohms");
mcp.Rheostats[0].Resistance = r;
await Task.Delay(1000);
}

Resolver.Log.Info("Done");
}

Sample project(s) available on GitHub