PHP code example of dept-of-scrapyard-robotics / bh1750

1. Go to this page and download the library: Download dept-of-scrapyard-robotics/bh1750 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dept-of-scrapyard-robotics / bh1750 example snippets



use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\BH1750;

return [
    'boards' => [
        'bh1750-native' => [
            'class_name' => BH1750::class,
            'connection' => [
                'driver' => 'native',
            ],
            'startup' => [
                'i2c' => [
                    'chip_device' => 1,
                    'slave_address' => 0x23,
                ],
            ],
        ],
        'bh1750-usb' => [
            'class_name' => BH1750::class,
            'connection' => [
                'driver' => 'usb',
            ],
            'startup' => [
                'i2c' => [
                    'chip_device' => 'ft232h',
                    'slave_address' => 0x23,
                ],
            ],
        ]              
    ]   
];


use RealityInterface\Sensors\Applied\AmbientLighting\AmbientLightSensor;

$bh1750 = AmbientLightSensor::using('bh1750-native');

$lux = $bh1750->getLuminance();


use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\BH1750;
use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\Enums\BH1750I2CAddress;

$native_sensor = BH1750::connection('native')
    ->i2c(1, BH1750I2CAddress::ADDR_GROUNDED->value)
    ->create();
    
$lux = $native_sensor->lux;


use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\Enums\BH1750WriteRegister;

$settings = $native_sensor->_settings;

$native_sensor->_settings = 0x10;
$native_sensor->_write = BH1750WriteRegister::RESET;

$raw = $native_sensor->_raw_reading;


use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\BH1750;
use DeptOfScrapyardRobotics\Sensors\BH1750\BH1750\Enums\BH1750I2CAddress;
use RealityInterface\Sensors\Applied\AmbientLighting\AmbientLightSensor;

$usb_sensor = BH1750::connection('usb')
    ->i2c('ft232h', BH1750I2CAddress::ADDR_GROUNDED->value)
    ->create();
    
$als = AmbientLightSensor::as($usb_sensor);

$lux = $als->getLuminance();



use RealityInterface\Sensors\Applied\AmbientLighting\AmbientLightSensor;

$bh1750 = AmbientLightSensor::using('bh1750-native');

// Simulated out-of-scope event measuring both sensors at the same time
$current_lux = $bh1750->getLuminance();
$ref = (int) "your-reference-lux";

// Add the values from your calibration session here. 
$bh1750 = $bh1750->calibrate($ref, $current_lux);

// The output of getLuminance() will now be adjusted with your compensation factor
// computed from the calibration.
$adjusted_lux = $bh1750->getLuminance();