Class LightSensorComponent

java.lang.Object
com.pi4j.crowpi.components.Component
com.pi4j.crowpi.components.LightSensorComponent

public class LightSensorComponent extends Component
Implementation of the CrowPi light sensor using I2C with Pi4J
  • Field Summary

    Fields inherited from class com.pi4j.crowpi.components.Component

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
    LightSensorComponent(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 Type
    Method
    Description
    protected double
    calculateLux(double measurementValue)
    Calculates Lux values from measurement values
    protected com.pi4j.io.i2c.I2C
    Returns the created PWM instance for the buzzer
    double
    Measure current light intensity with default resolution (1lx)
    double
    readLight(int resolution)
    Read current light intensity in lux with custom resolution settings

    Methods inherited from class com.pi4j.crowpi.components.Component

    sleep, triggerSimpleEvent

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 context
      bus - Custom I2C bus address
      device - 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