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 |
Characteristic | Locus |
---|---|
Inheritance | System.Object Hmc5883 > ThreeAxisDigitalCompass |
Inherited Members | Hmc5883.DirectionUpdated Hmc5883.Direction Hmc5883.Heading Hmc5883.DeviceStatus Hmc5883.Initialize() Meadow.Foundation.Sensors.Motion.Hmc5883.RaiseEventsAndNotify(IChangeResult<>) Hmc5883.ReadSensor() Hmc5883.DirectionToHeading(Vector) |
Namespace | Meadow.Foundation.Grove.Sensors.Motion |
Assembly | 3-AxisDigitalCompass.dll |
Syntax
public class ThreeAxisDigitalCompass : Hmc5883
Constructors
ThreeAxisDigitalCompass(II2cBus, Byte, Hmc5883.GainLevels, Hmc5883.MeasuringModes, Hmc5883.DataOutputRates, Hmc5883.SampleAmounts, Hmc5883.MeasurementConfigurations)
Creates a new ThreeAxisDigitalCompass driver
Declaration
public ThreeAxisDigitalCompass(II2cBus i2cBus, byte address = null, Hmc5883.GainLevels gain = default(Hmc5883.GainLevels), Hmc5883.MeasuringModes measuringMode = default(Hmc5883.MeasuringModes), Hmc5883.DataOutputRates outputRate = default(Hmc5883.DataOutputRates), Hmc5883.SampleAmounts samplesAmount = default(Hmc5883.SampleAmounts), Hmc5883.MeasurementConfigurations measurementConfig = default(Hmc5883.MeasurementConfigurations))
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | |
System.Byte | address | |
Hmc5883.GainLevels | gain | |
Hmc5883.MeasuringModes | measuringMode | |
Hmc5883.DataOutputRates | outputRate | |
Hmc5883.SampleAmounts | samplesAmount | |
Hmc5883.MeasurementConfigurations | measurementConfig |