鸿蒙开发板Hi3861_通过GPIO9光敏电阻实验code-2.0-CANARY
光敏电阻一个引脚接A9,另一引脚接GND
#include
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "iot_gpio.h"
#include "hi_io.h"
#include "iot_pwm.h"
#include "hi_pwm.h"
#include "hi_time.h"
#include "hi_adc.h"
static void adc_func(void *arg)
{
(void) arg;
unsigned short data=0;
while (1)
{
/* code */
if(hi_adc_read(HI_ADC_CHANNEL_4,&data,HI_ADC_EQU_MODEL_4,HI_ADC_CUR_BAIS_DEFAULT,0)==HI_ERR_SUCCESS)
{
printf("ADC_VALUE= %d\n",(unsigned int) data);
}
// hi_udelay(10);
osDelay(100);
data++;
}
}
SYS_RUN(adc_func);
build.gn
static_library("adc_demo") {
sources = [ "adc_demo1.c"]
include_dirs = [
"//third_party/cmsis/CMSIS/RTOS2/Include",
"//utils/native/lite/include",
"//kernel/liteos_m/components/cmsis/2.0",
"//base/iot_hardware/peripheral/interfaces/kits",
"//device/hisilicon/hispark_pegasus/sdk_liteos/include"
]
}
app/build.gn
# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//build/lite/config/component/lite_component.gni")
lite_component("app") {
features = [
"adc_demo",
]
}
当遮住无光时,ADC_VALUE 400+
感应到自然光时:ADC_VALUE 300+
参考:
https://harmonyos.51cto.com/posts/2273