Skip to main content

Meadow.Foundation.Sensors.Temperature.Mcp9808

Mcp9808
StatusStatus badge: working
Source codeGitHub
Datasheet(s)GitHub
NuGet packageNuGet Gallery for Meadow.Foundation.Sensors.Temperature.Mcp9808

Code Example

Mcp9808 mcp9808;

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

mcp9808 = new Mcp9808(Device.CreateI2cBus());

var consumer = Mcp9808.CreateObserver(
handler: result =>
{
Resolver.Log.Info($"Temperature New Value {result.New.Celsius}C");
Resolver.Log.Info($"Temperature Old Value {result.Old?.Celsius}C");
},
filter: null
);
mcp9808.Subscribe(consumer);

mcp9808.Updated += (object sender, IChangeResult<Meadow.Units.Temperature> e) =>
{
Resolver.Log.Info($"Temperature Updated: {e.New.Celsius:N2}C");
};

return Task.CompletedTask;
}

public override async Task Run()
{
var temp = await mcp9808.Read();

Resolver.Log.Info($"Temperature New Value {temp.Celsius}C");

mcp9808.StartUpdating(TimeSpan.FromSeconds(1));
}

Sample project(s) available on GitHub