upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Member Functions | Protected Attributes

API for the Light Sensor. More...

Detailed Description

The light sensor detects the intensity of the ambient light. As the light intensity of the environment increases, the resistance of the sensor decreases. This means the raw value from the analog pin is larger in bright light and smaller in the dark. A very approximate lux value can also be returned.

light.jpg
// Create the light sensor object using AIO pin 0
upm::Light light(0);
// Read the input and print both the normalized ADC value and a
// rough lux value, waiting one second between readings
while (1) {
std::cout << light.name() << " normalized value is " << light.getNormalized()
<< ", which is roughly " << light.value() << " lux" << std::endl;
upm_delay(1);
}
// Delete the light sensor object

Public Member Functions

 Light (unsigned int pin)
 
 ~Light ()
 
float raw_value ()
 
int value ()
 
void setAref (float aref)
 
void setScale (float scale)
 
void setOffset (float offset)
 
float getAref ()
 
float getScale ()
 
float getOffset ()
 
float getNormalized ()
 
float getRawVolts ()
 
std::string name ()
 

Protected Attributes

light_context m_light
 

Constructor & Destructor Documentation

Light ( unsigned int  pin)

Analog light sensor constructor

Parameters
pinAnalog pin to use
Exceptions
std::runtime_erroron initialization error
~Light ( )

Light destructor

Here is the call graph for this function:

Member Function Documentation

float raw_value ( )

Gets the raw value from the AIO pin

Deprecated:
This function is deprecated use getNormalized() instead.
Returns
Raw value from the ADC
Exceptions
std::runtime_erroron error

Here is the call graph for this function:

int value ( )

Gets an approximate light value in lux from the sensor

Returns
Approximate light reading in lux
Exceptions
std::runtime_erroron error

Here is the call graph for this function:

Here is the caller graph for this function:

void setAref ( float  aref)

Set ADC reference voltage

Parameters
arefADC reference voltage

Here is the call graph for this function:

void setScale ( float  scale)

Set sensor scale. This scale is applied to the return value: counts = counts * scale

Parameters
scalecount scale value used

Here is the call graph for this function:

void setOffset ( float  offset)

Set sensor offset. This offset is applied to the return value: value = value + offset

Parameters
offsetcount offset value used
Returns
Function result code

Here is the call graph for this function:

float getAref ( )

Get sensor aref

Parameters
devsensor context pointer
Returns
Sensor ADC reference voltage

Here is the call graph for this function:

float getScale ( )

Get sensor scale

Parameters
devsensor context pointer
Returns
Sensor scale

Here is the call graph for this function:

float getOffset ( )

Get sensor offset

Parameters
devsensor context pointer
Returns
Sensor offset

Here is the call graph for this function:

float getNormalized ( )

Read normalized value for sensor

Parameters
devsensor context pointer
*valueNormalized value (0.0 -> 1.0)
Returns
Function result code
Exceptions
std::runtime_erroron error

Here is the call graph for this function:

float getRawVolts ( )

Read raw voltage from the sensor

Parameters
devsensor context pointer
*valueRaw sensor voltage
Returns
Function result code
Exceptions
std::runtime_erroron error

Here is the call graph for this function:

Collaboration diagram for Light:
Collaboration graph
[legend]

The documentation for this class was generated from the following files: