esp-open-rtos/examples/bh1750/bh1750_example.c

45 lines
915 B
C
Raw Normal View History

#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
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);
while (1) {
while(1) {
vTaskDelay(200 / portTICK_PERIOD_MS);
2017-09-01 09:29:32 +00:00
printf("Lux: %d\n", bh1750_read(&dev));
}
}
}
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);
xTaskCreate(measure, "measure_task", 256, NULL, 2, NULL);
}