Bearpi开发板HarmonyOS之ADC采样

news/2024/7/21 8:13:33 标签: harmonyos, Bearpi开发板, ADC

wifiiot_adc.h接口简介

在这里插入图片描述

ADC_2">创建任务1秒读取一次ADC

#include <stdio.h>
#include <unistd.h>
#include "ohos_init.h"
#include <string.h>
#include "cmsis_os2.h"
#include "wifiiot_gpio.h"
#include "wifiiot_gpio_ex.h"
#include "wifiiot_adc.h"
#include "wifiiot_errno.h"


static float get_voltage(void)
{
  unsigned int ret;
  unsigned short data;
  ret = AdcRead(WIFI_IOT_ADC_CHANNEL_5,&data,WIFI_IOT_ADC_EQU_MODEL_8,WIFI_IOT_ADC_CUR_BAIS_DEFAULT,0xff);
  if (ret != WIFI_IOT_SUCCESS) 
  {
    printf("ADC Read Fail\n");
  }
  return (float)data*1.8f*4/4096;
}

static void adc_func(void)
{
  
    GpioInit();
    IoSetPull(WIFI_IOT_IO_NAME_GPIO_11,WIFI_IOT_IO_PULL_UP);
     float voltage;
    
     
      while(1)
      {
         voltage = get_voltage();
         printf("voltage:%.3fV\n", voltage);

         osDelay(100);
       
      }
}

static void my_led_example(void)
{
   
    
     osThreadAttr_t attr;
     attr.attr_bits = 0;
     attr.name = "adc";
     attr.cb_mem = NULL;
     attr.cb_size = 0;
     attr.priority = 24;
     attr.stack_size = 1024*8;

     if(osThreadNew((osThreadFunc_t)adc_func,NULL,&attr) == NULL)
     {
        printf("Falied to create adc_func!\n");
    }
}

SYS_RUN(my_led_example);
  • 运行效果,通过按键1改变电压值
    在这里插入图片描述

http://www.niftyadmin.cn/n/1226515.html

相关文章

ARM Mbed声控门禁

硬件 软件 介绍 现代手机具有许多有用的功能&#xff0c;可以丰富您的物联网项目。 在这个项目中&#xff0c;我们将使用Android手机的语音识别功能&#xff0c;使语音控制器进入门禁。 我们将使用MIT App Inventor 2&#xff08;AI2&#xff09;开发电话应用程序&#xff0…

Bearpi开发板HarmonyOS之UART读写

wifiiot_uart.h中包含声明UART接口函数 初始化UART unsigned int UartInit(WifiIotUartIdx id, const WifiIotUartAttribute *param, const WifiIotUartExtraAttr *extraAttr);取消UART初始化 unsigned int UartDeinit(WifiIotUartIdx id);从UART读取数据 int UartRead(WifiIo…

MQTT消息控制车辆Python实践

现在&#xff0c;我们将使用Python作为主要的编程语言来生成将充当发布者和订阅者的MQTT客户端。 我们将Python MQTT客户端连接到MQTT服务器&#xff0c;并处理命令以使用MQTT消息控制小型车辆。 小型车辆具有现实道路车辆所具有的许多功能。 我们将使用TLS加密和TLS身份验证&…

Bearpi开发板HarmonyOS之 WiFi AP热点

wifi_hotspot.h接口简介 启用AP热点模式 WifiErrorCode EnableHotspot(void);禁用AP热点模式 WifiErrorCode DisableHotspot(void);设置指定的热点配置 WifiErrorCode SetHotspotConfig(const HotspotConfig* config);获取指定的热点配置 WifiErrorCode GetHotspotConfig(Hots…

Bearpi开发板HarmonyOS之WiFi STA联网

wifi_device.h接口简介 启用Wifi STA 模式 WifiErrorCode EnableWifi(void); 禁用Wifi STA 模式 WifiErrorCode DisableWifi(void); 检查Wifi STA模式是否启用 int IsWifiActive(void); 扫描热点信息 WifiErrorCode Scan(void); 获取所有扫描到的热点列表 WifiErrorCode Ge…

Raspberry Pi 与Arduino SPI通信

本教程介绍了使用SPI&#xff08;串行外围设备接口总线&#xff09;进行Raspberry Pi与Arduino通讯和控制的基本框架。 SPI代表了一种非常完善的芯片间通信方法&#xff0c;该方法在两种设备的硬件中均实现。 在这里&#xff0c;我们将详细探讨SPI&#xff0c;讨论硬件和软件注…

LVGL V8.2.0之Axis ticks and labels with scrolling

绘制函数回调 static void draw_event_cb(lv_event_t* e) {lv_obj_draw_part_dsc_t* dsc lv_event_get_draw_part_dsc(e); //获取事件对象绘制描述符指针if (!lv_obj_draw_part_check_type(dsc, &lv_chart_class, LV_CHART_DRAW_PART_TICK_LABEL)) return; // LV_CHART_D…

Arduino对Flexinol精确位置控制

Flexinol&#xff0c;也称为肌肉线&#xff0c;是一种由镍钛诺制成的结实轻巧的电线&#xff0c;可以在导电时收缩。 在本文中&#xff0c;我将基于控制Flexinol电路中的电压&#xff0c;提出一种精确控制这种效果的方法。 此外&#xff0c;利用Flexinol的电阻随着收缩而可预测…