功能说明:
原型:
bool begin(Ltr5xx_Init_Basic_Para *init_base_para);
bool begin(Ltr5xx_Init_Interrupt_Para *init_interrupt_para);
参数:
参数 | 类型 | 描述 |
---|---|---|
init_base_para | Ltr5xx_Init_Basic_Para * | 基本监测初始化 |
init_interrupt_para | Ltr5xx_Init_Interrupt_Para * | 中断监测初始化 |
返回值:
返回值 | 描述 |
---|---|
true | 初始化成功 |
false | 初始化失败 |
功能说明:
原型:
bool setPsMode(uint8_t mode);
参数:
参数 | 类型 | 描述 |
---|---|---|
mode | uint8_t | 1: 启用接近传感器监测 0:传感器待机 |
返回值:
返回值 | 描述 |
---|---|
true | 初始化成功 |
false | 初始化失败 |
功能说明:
原型:
bool setAlsMode(uint8_t mode);
参数:
参数 | 类型 | 描述 |
---|---|---|
mode | uint8_t | 1: 启用环境光传感器监测 0:传感器待机 |
返回值:
返回值 | 描述 |
---|---|
true | 初始化成功 |
false | 初始化失败 |
功能说明:
原型:
uint16_t getPsValue(void);
参数:
None
返回值:
返回值 | 描述 |
---|---|
uint16_t | 监测距离模拟值 |
功能说明:
原型:
uint16_t getAlsValue(void);
参数:
None
返回值:
返回值 | 描述 |
---|---|
uint16_t | 监测环境光lux |
案例程序:
#include "M5CoreS3.h" Ltr5xx_Init_Basic_Para device_init_base_para = LTR5XX_BASE_PARA_CONFIG_DEFAULT; uint16_t read_ps_value;uint16_t read_als_value; void setup() { auto cfg = M5.config(); CoreS3.begin(cfg); CoreS3.Display.setTextColor(GREEN); CoreS3.Display.setTextDatum(middle_center); CoreS3.Display.setFont(&fonts::Orbitron_Light_24); CoreS3.Display.setTextSize(1); device_init_base_para.ps_led_pulse_freq = LTR5XX_LED_PULSE_FREQ_40KHZ; device_init_base_para.ps_measurement_rate = LTR5XX_PS_MEASUREMENT_RATE_50MS; device_init_base_para.als_gain = LTR5XX_ALS_GAIN_48X; if (!CoreS3.Ltr553.begin(&device_init_base_para)) { CoreS3.Display.drawString("Ltr553 Init Fail", CoreS3.Display.width() / 2, CoreS3.Display.height() / 2); while (1) { delay(10); } } CoreS3.Display.drawString("Ltr553 Init Success", CoreS3.Display.width() / 2, CoreS3.Display.height() / 2); // active ps CoreS3.Ltr553.setPsMode(LTR5XX_PS_ACTIVE_MODE); // active als CoreS3.Ltr553.setAlsMode(LTR5XX_ALS_ACTIVE_MODE); // not active ps // CoreS3.Ltr553.setPsMode(LTR5XX_PS_STAND_BY_MODE); // not active als // CoreS3.Ltr553.setAlsMode(LTR5XX_ALS_STAND_BY_MODE);} void loop() { CoreS3.Display.clear(); read_ps_value = CoreS3.Ltr553.getPsValue(); read_als_value = CoreS3.Ltr553.getAlsValue(); CoreS3.Display.drawString( "PS:" + String(read_ps_value) + " / " + "ALS:" + String(read_als_value), CoreS3.Display.width() / 2, CoreS3.Display.height() / 2); Serial.printf("ps value = %d\r\n", read_ps_value); Serial.printf("als value = %d\r\n", read_als_value); delay(100);}