Read and calibrate photoresistors.
See Example Public Methods Release NotesRead and calibrate photoresistors; also known as light-dependent resistors (LDR). Calibrate light threshold levels with setFloor() and setCeiling(), then use getValue() or getPercentValue() to read the value.
#include <RBD_LightSensor.h> RBD::LightSensor light_sensor(A0); void setup() { Serial.begin(115200); } void loop() { Serial.println(light_sensor.getPercentValue()); }
RBD::LightSensor
Create a new sensor and pass in the Arduino pin number.
RBD::LightSensor light_sensor(A0); void setup() { ... }
Returns an integer from 0 - 1023 for the current light level adjusted for the setFloor() and setCeiling() values. If the floor or ceiling are not set, this method will return getRawValue().
void loop() { light_sensor.getValue(); }
Returns an integer from 0 - 1023 for the current light level reading from the sensor. Use this method to calibrate setFloor() and setCeiling().
void loop() { light_sensor.getRawValue(); }
Returns an integer from 0 - 100 for the current light percentage.
void loop() { light_sensor.getPercentValue(); }
Returns an integer from 1023 - 0 for the opposite of the current light level.
void loop() { light_sensor.getInverseValue(); }
Returns an integer from 100 - 0 for the opposite of the current light percentage.
void loop() { light_sensor.getInversePercentValue(); }
Provide an integer from 0 - 1023 to calibrate the sensor with a lower bounds of light detection. This will adjust the scale for all methods that return a value in this library, but will not adjust their documented output range. Calibrate the floor with help from getRawValue().
void setup() { light_sensor.setFloor(10); }
Provide an integer from 0 - 1023 to calibrate the sensor with an upper bounds of light detection. This will adjust the scale for all methods that return a value in this library, but will not adjust their documented output range. Calibrate the ceiling with help from getRawValue().
void setup() { light_sensor.setCeiling(999); }
Change the setFloor() value back to 0, which also resets the lower bounds of the scale for all methods that return a value in this library.
void setup() { light_sensor.resetFloor(); }
Change the setCeiling() value back to 1023, which also resets the upper bounds of the scale for all methods that return a value in this library.
void setup() { light_sensor.resetCeiling(); }