bh1750 i2c light sensor driver + pwm cleanup (#330)

Add bh1750 (I2C light sensor) driver + usage example
This commit is contained in:
andree182 2017-04-01 02:20:37 +02:00 committed by Ruslan V. Uss
parent 31ef50c9a9
commit b3f658bdbf
7 changed files with 170 additions and 7 deletions

28
extras/bh1750/bh1750.c Normal file
View file

@ -0,0 +1,28 @@
/*
* Driver for BH1750 light sensor
*
* Part of esp-open-rtos
* Copyright (C) 2017 Andrej Krutak <dev@andree.sk>
* BSD Licensed as described in the file LICENSE
*/
#include "bh1750.h"
#include <i2c/i2c.h>
#include <stdio.h>
void bh1750_configure(uint8_t addr, uint8_t mode)
{
i2c_slave_write(addr, NULL, &mode, 1);
}
uint16_t bh1750_read(uint8_t addr)
{
uint8_t buf[2];
uint16_t level;
i2c_slave_read(addr, NULL, buf, 2);
level = buf[0] << 8 | buf[1];
level = (level * 10) / 12; // convert to LUX
return level;
}