mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-19 01:15:54 +08:00
[update] 增加STM32智慧宿舍基础代码
This commit is contained in:
42
firmware/stm32/smart_dormitory/User/light/sensor_light.c
Normal file
42
firmware/stm32/smart_dormitory/User/light/sensor_light.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/****************************************Copyright (c)****************************************************
|
||||
**
|
||||
** File name: process.c
|
||||
** Created by: XiaoYi
|
||||
** Created date: 2020-10-16
|
||||
** Version: v1.0
|
||||
** Descriptions: The original
|
||||
** Link address: https://blog.csdn.net/weixin_45006076
|
||||
**
|
||||
*********************************************************************************************************/
|
||||
|
||||
#include "sensor_light.h"
|
||||
#include "gpio.h"
|
||||
#include "adc.h"
|
||||
|
||||
uint16_t light_get_value(void)
|
||||
{
|
||||
// <20><><EFBFBD><EFBFBD>ADCת<43><D7AA>
|
||||
HAL_ADC_Start(&hadc1);
|
||||
// <20>ȴ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3>ڶ<EFBFBD><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ʱʱ<CAB1>䣬<EFBFBD><E4A3AC>λms
|
||||
HAL_ADC_PollForConversion(&hadc1, 100);
|
||||
return HAL_ADC_GetValue(&hadc1);
|
||||
}
|
||||
|
||||
uint8_t light_get_average_value(uint8_t times) //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
{
|
||||
uint32_t temp_val=0;
|
||||
uint8_t t;
|
||||
float temp_avrg=0;
|
||||
|
||||
for(t=0;t<times;t++) //LSENS_READ_TIMES<45><53>lsens.h<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>Ĭ<EFBFBD><C4AC>10//
|
||||
{
|
||||
temp_val += light_get_value(); //<2F><>ȡADCֵ
|
||||
delay_ms(5);
|
||||
}
|
||||
temp_val/=times; //<2F><><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>ֵ//
|
||||
if(temp_val>4000)
|
||||
temp_val=4000; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>4000ʱ<30><CAB1>ǿ<EFBFBD><C7BF>ת<EFBFBD><D7AA>Ϊ4000//
|
||||
|
||||
return (100-(temp_val/40)); //<2F><>temp_valֵ<6C><D6B5>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>0-100֮<30><D6AE>//
|
||||
}
|
||||
|
||||
19
firmware/stm32/smart_dormitory/User/light/sensor_light.h
Normal file
19
firmware/stm32/smart_dormitory/User/light/sensor_light.h
Normal file
@@ -0,0 +1,19 @@
|
||||
/****************************************Copyright (c)****************************************************
|
||||
**
|
||||
** File name: light.h
|
||||
** Created by: XiaoYi
|
||||
** Created date: 2020-10-16
|
||||
** Version: v1.0
|
||||
** Descriptions: The original
|
||||
** Link address: https://blog.csdn.net/weixin_45006076
|
||||
**
|
||||
*********************************************************************************************************/
|
||||
|
||||
#ifndef __SENSOR_LIGHT_H__
|
||||
#define __SENSOR_LIGHT_H__
|
||||
|
||||
#include "main.h"
|
||||
|
||||
uint8_t light_get_average_value(uint8_t times);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user