Library for digital light sensor BH1750 (GY-30). SPI Test Comunication with ArduinoMega

Embed: (wiki syntax)

« Back to documentation index

BH1750 Class Reference

BH1750 Class Reference

#include <BH1750.h>

Public Member Functions

 BH1750 (PinName sda, PinName slc)
void init (char mode=BH1750_CONTINUOUS_HIGH_RES_MODE)
 Initialize sensor with specified mode.
void configure (char mode)
 Configure sensor with specified mode.
float readIntesity (void)
 Read light intensity.
char * getRawData (void)
 Get raw data obtained after sucessfull executing of readIntesity(void).
int getStatus (void)

Detailed Description

 #include "mbed.h"
 #include "BH1750.h"

 BH1750  lightSensor(I2C_SDA, I2C_SCL);
 Serial pc(SERIAL_TX, SERIAL_RX);

 int main() 
 {
    lightSensor.init();

    while(1) {
        pc.printf("Light intensity: %.4f Lux\r\n", lightSensor.readIntesity());
        wait(5);
    }
 }

Definition at line 74 of file BH1750.h.


Constructor & Destructor Documentation

BH1750 ( PinName  sda,
PinName  slc 
)
Parameters:
sda
scl

Definition at line 5 of file BH1750.cpp.


Member Function Documentation

void configure ( char  mode )

Configure sensor with specified mode.

This function is called also in init(char);

Parameters:
modeof sensor operation.

Definition at line 18 of file BH1750.cpp.

char * getRawData ( void   )

Get raw data obtained after sucessfull executing of readIntesity(void).

Returns:
unprocessed raw data readed from sensor.

Definition at line 55 of file BH1750.cpp.

int getStatus ( void   )
Returns:
0 no error. !=0 I2C error code.

Definition at line 50 of file BH1750.cpp.

void init ( char  mode = BH1750_CONTINUOUS_HIGH_RES_MODE )

Initialize sensor with specified mode.

Default mode is set to BH1750_CONTINUOUS_HIGH_RES_MODE.

Parameters:
modeof sensor operation.

Definition at line 12 of file BH1750.cpp.

float readIntesity ( void   )

Read light intensity.

In addition also error code and raw data are filled.

Returns:
light intensity in Lux.

Definition at line 38 of file BH1750.cpp.