Ambient Light Sensor¶
Ambient light sensors convert light intensity into a digital signal using a combination of photodiodes and analog-to-digital converters. The light sensor of choice on select boards is the LTR-329ALS device from Lite-On, represented by the IAmbientLightLtr329 interface.
using MbientLab.MetaWear.Sensor;
IAmbientLightLtr329 alsLtr329 = metawear.GetModule<IAmbientLightLtr329>();
Configuration¶
The sensor has three configurable parameters, set with the module’s Configure function:
Parameter | Description |
---|---|
Gain | Controls data range and resolution |
Integration Time | Measurement time for each cycle |
Measurement Rate | How frequently to update illuminance data |
using MbientLab.MetaWear.Sensor.AmbientLightLtr329;
// Set the gain to 8x
// Set integration time to 250ms
// Set measurement rate to 50ms
alsLtr329.Configure(gain: Gain._8x, time: IntegrationTime._250ms, rate: MeasurementRate._50ms);
Illuminance Data¶
Illuminance data is categorized as an async data producer; data is interpreted as a float value and is in units of lux (lx).
await als.Illuminance.AddRouteAsync(source =>
source.Stream(data => Console.WriteLine("illuminance = " + data.Value<float>()))
);