Add bh1750 usage example

This commit is contained in:
Andrej Krutak 2017-03-30 22:07:51 +02:00 committed by Andrej Krutak
parent c03622871f
commit ab5e1eb5d6
2 changed files with 44 additions and 0 deletions

3
examples/bh1750/Makefile Normal file
View file

@ -0,0 +1,3 @@
PROGRAM=bh1750_example
EXTRA_COMPONENTS = extras/i2c extras/bh1750
include ../../common.mk

View file

@ -0,0 +1,41 @@
#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
static void measure(void *pvParameters)
{
bh1750_configure(BH1750_ADDR_LO,
BH1750_CONTINUOUS_MODE | BH1750_HIGH_RES_MODE);
while (1) {
while(1) {
vTaskDelay(200 / portTICK_PERIOD_MS);
printf("Lux: %d\n", bh1750_read(BH1750_ADDR_LO));
}
}
}
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);
i2c_init(SCL_PIN, SDA_PIN);
xTaskCreate(measure, "measure_task", 256, NULL, 2, NULL);
}