Remarks
3-AxisDigitalCompass | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
Code Example
ThreeAxisDigitalCompass sensor;
public override Task Initialize()
{
Console.WriteLine("Initializing ...");
sensor = new ThreeAxisDigitalCompass(Device.CreateI2cBus());
sensor.Updated += (sender, result) => {
Console.WriteLine($"Direction: [X:{result.New.X:N2}," +
$"Y:{result.New.Y:N2}," +
$"Z:{result.New.Z:N2}]");
Console.WriteLine($"Heading: [{Hmc5883.DirectionToHeading(result.New).DecimalDegrees:N2}] degrees");
};
var consumer = Hmc5883.CreateObserver(
handler: result =>
{
Console.WriteLine($"Observer: [x] changed by threshold; " +
$"new [x]: X:{Hmc5883.DirectionToHeading(result.New):N2}, " +
$"old: X:{((result.Old != null) ? Hmc5883.DirectionToHeading(result.Old.Value) : "n/a"):N2} degrees");
},
filter: result => {
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
return (Hmc5883.DirectionToHeading(result.New - old) > new Azimuth(5));
}
return false;
});
sensor.Subscribe(consumer);
return Task.CompletedTask;
}
public override Task Run()
{
sensor.StartUpdating(TimeSpan.FromSeconds(1));
return Task.CompletedTask;
}
Sample project(s) available on GitHub
Wiring Example
ThreeAxisDigitalCompass | Meadow Pin |
---|---|
GND | GND |
VCC | 3.3V |
RX | D01 |
TX | D00 |
Syntax
public class ThreeAxisDigitalCompass : Hmc5883, IObservable<IChangeResult<Vector>>, ISamplingSensor<Vector>, ISensor<Vector>, IDisposable, II2cPeripheral
Constructors
ThreeAxisDigitalCompass(II2cBus, byte, GainLevels, MeasuringModes, DataOutputRates, SampleAmounts, MeasurementConfigurations)
Creates a new ThreeAxisDigitalCompass driver
Declaration
public ThreeAxisDigitalCompass(II2cBus i2cBus, byte address = 30, Hmc5883.GainLevels gain = GainLevels.Gain1090, Hmc5883.MeasuringModes measuringMode = MeasuringModes.Continuous, Hmc5883.DataOutputRates outputRate = DataOutputRates.Rate15, Hmc5883.SampleAmounts samplesAmount = SampleAmounts.One, Hmc5883.MeasurementConfigurations measurementConfig = MeasurementConfigurations.Normal)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | |
byte | address | |
Hmc5883.GainLevels | gain | |
Hmc5883.MeasuringModes | measuringMode | |
Hmc5883.DataOutputRates | outputRate | |
Hmc5883.SampleAmounts | samplesAmount | |
Hmc5883.MeasurementConfigurations | measurementConfig |
Remarks
3-AxisDigitalCompass | |
---|---|
Status | |
Source code | GitHub |
NuGet package |
Code Example
ThreeAxisDigitalCompass sensor;
public override Task Initialize()
{
Console.WriteLine("Initializing ...");
sensor = new ThreeAxisDigitalCompass(Device.CreateI2cBus());
sensor.Updated += (sender, result) => {
Console.WriteLine($"Direction: [X:{result.New.X:N2}," +
$"Y:{result.New.Y:N2}," +
$"Z:{result.New.Z:N2}]");
Console.WriteLine($"Heading: [{Hmc5883.DirectionToHeading(result.New).DecimalDegrees:N2}] degrees");
};
var consumer = Hmc5883.CreateObserver(
handler: result =>
{
Console.WriteLine($"Observer: [x] changed by threshold; " +
$"new [x]: X:{Hmc5883.DirectionToHeading(result.New):N2}, " +
$"old: X:{((result.Old != null) ? Hmc5883.DirectionToHeading(result.Old.Value) : "n/a"):N2} degrees");
},
filter: result => {
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
return (Hmc5883.DirectionToHeading(result.New - old) > new Azimuth(5));
}
return false;
});
sensor.Subscribe(consumer);
return Task.CompletedTask;
}
public override Task Run()
{
sensor.StartUpdating(TimeSpan.FromSeconds(1));
return Task.CompletedTask;
}
Sample project(s) available on GitHub
Wiring Example
ThreeAxisDigitalCompass | Meadow Pin |
---|---|
GND | GND |
VCC | 3.3V |
RX | D01 |
TX | D00 |