2017-04-01 00:20:37 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "espressif/esp_common.h"
|
|
|
|
#include "esp/uart.h"
|
|
|
|
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#include "task.h"
|
|
|
|
|
|
|
|
#include "i2c/i2c.h"
|
|
|
|
#include "bh1750/bh1750.h"
|
|
|
|
|
|
|
|
#define SCL_PIN 5
|
|
|
|
#define SDA_PIN 4
|
2017-09-01 09:29:32 +00:00
|
|
|
#define I2C_BUS 0
|
2017-04-01 00:20:37 +00:00
|
|
|
|
|
|
|
static void measure(void *pvParameters)
|
|
|
|
{
|
2017-09-01 09:29:32 +00:00
|
|
|
i2c_dev_t dev = {
|
|
|
|
.addr = BH1750_ADDR_LO,
|
|
|
|
.bus = I2C_BUS,
|
|
|
|
};
|
|
|
|
bh1750_configure(&dev, BH1750_CONTINUOUS_MODE | BH1750_HIGH_RES_MODE);
|
2017-04-01 00:20:37 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
while(1) {
|
|
|
|
vTaskDelay(200 / portTICK_PERIOD_MS);
|
2017-09-01 09:29:32 +00:00
|
|
|
printf("Lux: %d\n", bh1750_read(&dev));
|
2017-04-01 00:20:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void user_init(void)
|
|
|
|
{
|
|
|
|
uart_set_baud(0, 115200);
|
|
|
|
|
|
|
|
// Just some information
|
|
|
|
printf("\n");
|
|
|
|
printf("SDK version : %s\n", sdk_system_get_sdk_version());
|
|
|
|
printf("GIT version : %s\n", GITSHORTREV);
|
|
|
|
|
2017-09-01 09:29:32 +00:00
|
|
|
i2c_init(I2C_BUS, SCL_PIN, SDA_PIN, I2C_FREQ_100K);
|
2017-04-01 00:20:37 +00:00
|
|
|
|
|
|
|
xTaskCreate(measure, "measure_task", 256, NULL, 2, NULL);
|
|
|
|
}
|