1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/init.h> 9 #include <stdio.h> 10 #include <zephyr/drivers/sensor.h> 11 12 #define SLEEP_TIME K_MSEC(1000) 13 main(void)14int main(void) 15 { 16 const struct device *const dev = DEVICE_DT_GET_ONE(seeed_grove_light); 17 18 if (!device_is_ready(dev)) { 19 printk("sensor: device not ready.\n"); 20 return 0; 21 } 22 23 while (1) { 24 int read; 25 struct sensor_value lux; 26 27 read = sensor_sample_fetch(dev); 28 if (read) { 29 printf("sample fetch error %d\n", read); 30 continue; 31 } 32 33 sensor_channel_get(dev, SENSOR_CHAN_LIGHT, &lux); 34 35 printf("lux: %f\n", sensor_value_to_double(&lux)); 36 37 k_sleep(SLEEP_TIME); 38 } 39 return 0; 40 } 41