原创
【RT-Thread软件包+w601评测】②光敏联动LED灯光
接《【RT-Thread软件包+w601评测】①开箱测评》第一个想到的是光敏开关控制摄像头模组的日夜模式,并开启补光灯,但是搜了一下貌似这个板子不支持原子的摄像头模组,所以现在改成光敏开启LED补光灯。
不得不说RT-Thread对没有RT OS和LIUNX经验的人来说很不友好,虽然有完整开发教程和例程,入手起来仍有须努力,裸板的程序虽然繁琐但是很好理解也很好做,RT Thread需要熟悉API,程序据了解的同事说是LINUX风格。(开发板的资料下载链接:https://pan.baidu.com/s/1UwbrQBbNt3Vnf9DGoETymg 提取码:q6dc
)。
开发板资料目录
![](https://static.assets-stash.eet-china.com/album/201912/04/231905dr7y4993tt6tp4wy.png)
使用官方推荐的串口助手烧写.FLS格式文件(文件路径尽量不要有中文,我使用时候烧写失败过,放根目录下就好了)。
![](https://static.assets-stash.eet-china.com/album/201912/04/232705mr66aff1flfarsfs.png)
运行结果
![](https://static.assets-stash.eet-china.com/album/201912/04/231906an87p79vznc9nnb7.jpg)
![](https://static.assets-stash.eet-china.com/album/201912/04/231911enk0kkdc78lbk78n.jpg)
本来想做个接近报警并联动阿里云,但是RT Thread还是不太熟悉。听说TR Thread有线下培训活动,希望有机会可以参加。
附源码
#include <rtthread.h>#include <rtdevice.h>#include "board.h"#define DBG_TAG "main"#define DBG_LVL DBG_LOG#include <rtdbg.h>#include "sensor_lsc_ap3216c.h"#define DBG_TAG "main"#define DBG_LVL DBG_LOG#include <rtdbg.h>#define ALS_DEV "li_ap321"#define PS_DEV "pr_ap321"/* 配置 LED 灯引脚 */#define LED_PIN PIN_LED_Rint main(void){ /* 设置 LED 引脚为输出模式 */ rt_pin_mode(LED_PIN, PIN_MODE_OUTPUT); int count = 0; rt_device_t als_dev, ps_dev; struct rt_sensor_data als_dev_data, ps_dev_data; LOG_D("Als Ps Sensor Testing Start..."); /* 查找并打开光强传感器 */ als_dev = rt_device_find(ALS_DEV); if (als_dev == RT_NULL) { LOG_E("can not find ALS device: %s", ALS_DEV); return -RT_ERROR; } else { if (rt_device_open(als_dev, RT_DEVICE_FLAG_RDONLY) != RT_EOK) { LOG_E("open ALS device failed!"); return -RT_ERROR; } } /* 查找并打开接近传感器 */ ps_dev = rt_device_find(PS_DEV); if (ps_dev == RT_NULL) { LOG_E("can not find PS device: %s", PS_DEV); return -RT_ERROR; } else { if (rt_device_open(ps_dev, RT_DEVICE_FLAG_RDONLY) != RT_EOK) { LOG_E("open PS device failed!"); return -RT_ERROR; } } /* 开始读取传感器数据 */ while (count <1000) { rt_device_read(als_dev, 0, &als_dev_data, 1); LOG_D("current brightness: %d.%d(lux).", (int)(als_dev_data.data.light / 10), (int)(als_dev_data.data.light % 10)); rt_device_read(ps_dev, 0, &ps_dev_data, 1); if (als_dev_data.data.proximity < 10) { rt_pin_write(LED_PIN, PIN_LOW); LOG_D("led on, count: %d", count); } else { rt_pin_write(LED_PIN, PIN_HIGH); LOG_D("led off"); } rt_thread_mdelay(100); } rt_device_close(als_dev); rt_device_close(ps_dev); LOG_D("Als Ps Sensor Testing Ended."); return RT_EOK;}复制代码
作者: DrouSherry, 来源:面包板社区
链接: https://mbb.eet-china.com/blog/uid-me-1715169.html
版权声明:本文为博主原创,未经本人允许,禁止转载!
关闭
站长推荐
/3
用户3925113 2020-7-30 09:55
curton 2019-12-7 19:34
7sms 2019-12-6 14:02