java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.LightSensorComponent
Implementation of the CrowPi light sensor using I2C with Pi4J
-
Field Summary
-
Constructor Summary
ConstructorDescriptionLightSensorComponent
(com.pi4j.context.Context pi4j) Creates a new light sensor component using the default setup.LightSensorComponent
(com.pi4j.context.Context pi4j, int bus, int device) Creates a new light sensor component with custom bus, device address -
Method Summary
Modifier and TypeMethodDescriptionprotected double
calculateLux
(double measurementValue) Calculates Lux values from measurement valuesprotected com.pi4j.io.i2c.I2C
getI2C()
Returns the created PWM instance for the buzzerdouble
Measure current light intensity with default resolution (1lx)double
readLight
(int resolution) Read current light intensity in lux with custom resolution settingsMethods inherited from class com.pi4j.crowpi.components.Component
sleep, triggerSimpleEvent
-
Constructor Details
-
LightSensorComponent
public LightSensorComponent(com.pi4j.context.Context pi4j) Creates a new light sensor component using the default setup.- Parameters:
pi4j
- Pi4J context
-
LightSensorComponent
public LightSensorComponent(com.pi4j.context.Context pi4j, int bus, int device) Creates a new light sensor component with custom bus, device address- Parameters:
pi4j
- Pi4J contextbus
- Custom I2C bus addressdevice
- Custom device address on I2C
-
-
Method Details
-
readLight
public double readLight(int resolution) Read current light intensity in lux with custom resolution settings- Parameters:
resolution
- Defines resolution of measurements: 0 = 4lx Resolution / 1 = 1lx Resolution / 2 = 0.5lx Resolution- Returns:
- Light intensity in lux
-
readLight
public double readLight()Measure current light intensity with default resolution (1lx)- Returns:
- Light intensity in lux
-
calculateLux
protected double calculateLux(double measurementValue) Calculates Lux values from measurement values- Parameters:
measurementValue
- Measurement value from light sensor- Returns:
- Calculated value in lux
-
getI2C
protected com.pi4j.io.i2c.I2C getI2C()Returns the created PWM instance for the buzzer- Returns:
- I2C instance
-