Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Syntax
public class Bh1745 : ByteCommsSensorBase<(Illuminance? AmbientLight, Color? Color, bool Valid)>, IObservable<IChangeResult<(Illuminance? AmbientLight, Color? Color, bool Valid)>>, ISamplingSensor<(Illuminance? AmbientLight, Color? Color, bool Valid)>, ISensor<(Illuminance? AmbientLight, Color? Color, bool Valid)>, IDisposable, ILightSensor, ISamplingSensor<Illuminance>, ISensor<Illuminance>, II2cPeripheral
Constructors
Bh1745(II2cBus, byte)
Create a new BH17545 color sensor object
Declaration
public Bh1745(II2cBus i2cBus, byte address = 56)
Parameters
Type | Name | Description |
---|---|---|
II2cBus | i2cBus | |
byte | address |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Properties
AdcGain
Gets or sets the ADC gain of the sensor
Declaration
public Bh1745.AdcGainTypes AdcGain { get; set; }
Property Value
Type | Description |
---|---|
Bh1745.AdcGainTypes |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
CompensationMultipliers
Gets or sets the channel compensation multipliers which are used to scale the channel measurements
Declaration
public Bh1745.ChannelMultipliers CompensationMultipliers { get; set; }
Property Value
Type | Description |
---|---|
Bh1745.ChannelMultipliers |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
DefaultI2cAddress
The default I2C address for the peripheral
Declaration
public byte DefaultI2cAddress { get; }
Property Value
Type | Description |
---|---|
byte |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Illuminance
The current Illuminance value
Declaration
public Illuminance? Illuminance { get; }
Property Value
Type | Description |
---|---|
Illuminance? |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
InterruptIsEnabled
Gets or sets whether the interrupt pin is enabled
Declaration
public bool InterruptIsEnabled { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
InterruptPersistence
Gets or sets the persistence function of the interrupt
Declaration
public Bh1745.InterruptTypes InterruptPersistence { get; set; }
Property Value
Type | Description |
---|---|
Bh1745.InterruptTypes |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
InterruptReset
Interrupt reset status
Declaration
public Bh1745.InterruptStatus InterruptReset { get; set; }
Property Value
Type | Description |
---|---|
Bh1745.InterruptStatus |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
InterruptSignalIsActive
Is the interrupt active
Declaration
public bool InterruptSignalIsActive { get; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
InterruptSource
Gets or sets the source channel that triggers the interrupt
Declaration
public Bh1745.InterruptChannels InterruptSource { get; set; }
Property Value
Type | Description |
---|---|
Bh1745.InterruptChannels |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
IsMeasurementActive
Is the sensor actively measuring
Declaration
public bool IsMeasurementActive { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
LatchBehavior
Gets or sets how the interrupt pin latches
Declaration
public Bh1745.LatchBehaviorTypes LatchBehavior { get; set; }
Property Value
Type | Description |
---|---|
Bh1745.LatchBehaviorTypes |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
LowerInterruptThreshold
Gets or sets the lower interrupt threshold
Declaration
public ushort LowerInterruptThreshold { get; set; }
Property Value
Type | Description |
---|---|
ushort |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
MeasurementTime
Gets or sets the currently set measurement time
Declaration
public Bh1745.MeasurementTimeType MeasurementTime { get; set; }
Property Value
Type | Description |
---|---|
Bh1745.MeasurementTimeType |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
UpperInterruptThreshold
Gets or sets the upper interrupt threshold
Declaration
public ushort UpperInterruptThreshold { get; set; }
Property Value
Type | Description |
---|---|
ushort |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Methods
RaiseEventsAndNotify(IChangeResult<(Illuminance? AmbientLight, Color? Color, bool Valid)>)
Raise events for subcribers and notify of value changes
Declaration
protected override void RaiseEventsAndNotify(IChangeResult<(Illuminance? AmbientLight, Color? Color, bool Valid)> changeResult)
Parameters
Type | Name | Description |
---|---|---|
IChangeResult<(Illuminance? AmbientLight, Color? Color, bool Valid)> | changeResult | The updated sensor data |
Overrides
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
ReadBlueDataRegister()
Reads the blue data register of the sensor
Declaration
protected ushort ReadBlueDataRegister()
Returns
Type | Description |
---|---|
ushort |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
ReadClearDataRegister()
Reads the clear data register of the sensor
Declaration
protected ushort ReadClearDataRegister()
Returns
Type | Description |
---|---|
ushort |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
ReadGreenDataRegister()
Reads the green data register of the sensor
Declaration
protected ushort ReadGreenDataRegister()
Returns
Type | Description |
---|---|
ushort |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
ReadMeasurementIsValid()
Reads whether the last measurement is valid
Declaration
protected bool ReadMeasurementIsValid()
Returns
Type | Description |
---|---|
bool |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
ReadRedDataRegister()
Reads the red data register of the sensor
Declaration
protected ushort ReadRedDataRegister()
Returns
Type | Description |
---|---|
ushort |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
ReadSensor()
Reads data from the sensor
Declaration
protected override Task<(Illuminance? AmbientLight, Color? Color, bool Valid)> ReadSensor()
Returns
Type | Description |
---|---|
Task<(Illuminance? AmbientLight, Color? Color, bool Valid)> | The latest sensor reading |
Overrides
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Reset()
Resets the device to the default configuration On reset the sensor goes to power down mode
Declaration
protected void Reset()
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram:
Events
LuminosityUpdated
Raised when the luminosity changes
Declaration
public event EventHandler<IChangeResult<Illuminance>> LuminosityUpdated
Event Type
Type | Description |
---|---|
EventHandler<IChangeResult<Illuminance>> |
Remarks
Bh1745 | |
---|---|
Status | |
Source code | GitHub |
Datasheet(s) | GitHub |
NuGet package |
The BH1745 is a RGB color and luminance sensor that communicates over I2C.
Code Example
Bh1745 sensor;
RgbPwmLed rgbLed;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
sensor = new Bh1745(Device.CreateI2cBus());
// instantiate our onboard LED that we'll show the color with
rgbLed = new RgbPwmLed(
Device.Pins.OnboardLedRed,
Device.Pins.OnboardLedGreen,
Device.Pins.OnboardLedBlue,
commonType: CommonType.CommonAnode);
// Example that uses an IObservable subscription to only be notified
var consumer = Bh1745.CreateObserver(
handler: result => Resolver.Log.Info($"Observer: filter satisifed: {result.New.AmbientLight?.Lux:N2}Lux, old: {result.Old?.AmbientLight?.Lux:N2}Lux"),
// only notify if the visible light changes by 100 lux (put your hand over the sensor to trigger)
filter: result =>
{
if (result.Old is { } old)
{ //c# 8 pattern match syntax. checks for !null and assigns var.
// returns true if > 100lux change
return ((result.New.AmbientLight.Value - old.AmbientLight.Value).Abs().Lux > 100);
}
return false;
});
sensor.Subscribe(consumer);
//classical .NET events can also be used:
sensor.Updated += (sender, result) =>
{
Resolver.Log.Info($" Ambient Light: {result.New.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.New.Color}");
if (result.New.Color is { } color)
{
rgbLed.SetColor(color);
}
};
return Task.CompletedTask;
}
public override async Task Run()
{
var result = await sensor.Read();
Resolver.Log.Info("Initial Readings:");
Resolver.Log.Info($" Visible Light: {result.AmbientLight?.Lux:N2}Lux");
Resolver.Log.Info($" Color: {result.Color}");
if (result.Color is { } color)
{
rgbLed.SetColor(color);
}
sensor.StartUpdating(TimeSpan.FromSeconds(1));
}
Sample project(s) available on GitHub
Wiring Example
To wire a Bh1745 to your Meadow board, connect the following:
Bh1745 | Meadow Pin |
---|---|
GND | GND |
SCL | D08 (SCL) |
SDA | D07 (SDA) |
VCC | 3V3 |
It should look like the following diagram: