标题: Arduino HX711模块库文件下载 [打印本页]

作者: sh782945358    时间: 2019-6-10 00:05
标题: Arduino HX711模块库文件下载
有些乱,不过能看


Arduino源程序如下:
  1. #include "hx711.h"

  2. long HX711_Buffer = 0;
  3. long Weight_Maopi = 0,Weight_Shiwu = 0;

  4. #define GapValue 430

  5. //****************************************************
  6. //初始化HX711
  7. //****************************************************
  8. void Init_Hx711()
  9. {
  10.         pinMode(HX711_SCK, OUTPUT);       
  11.         pinMode(HX711_DT, INPUT);
  12. }


  13. //****************************************************
  14. //获取毛皮重量
  15. //****************************************************
  16. void Get_Maopi()
  17. {
  18.         Weight_Maopi = HX711_Read();               
  19. }

  20. //****************************************************
  21. //称重
  22. //****************************************************
  23. long Get_Weight()
  24. {
  25.         HX711_Buffer = HX711_Read();
  26.         Weight_Shiwu = HX711_Buffer;
  27.         Weight_Shiwu = Weight_Shiwu - Weight_Maopi;                                //获取实物的AD采样数值。
  28.         Weight_Shiwu = (long)((float)Weight_Shiwu/GapValue);        
  29.         return Weight_Shiwu;
  30. }

  31. //****************************************************
  32. //读取HX711
  33. //****************************************************
  34. unsigned long HX711_Read(void)        //增益128
  35. {
  36.         unsigned long count;
  37.         unsigned char i;
  38.         bool Flag = 0;

  39.         digitalWrite(HX711_DT, HIGH);
  40.         delayMicroseconds(1);

  41.         digitalWrite(HX711_SCK, LOW);
  42.         delayMicroseconds(1);

  43.           count=0;
  44.           while(digitalRead(HX711_DT));
  45.           for(i=0;i<24;i++)
  46.         {
  47.                   digitalWrite(HX711_SCK, HIGH);
  48.                 delayMicroseconds(1);
  49.                   count=count<<1;
  50.                 digitalWrite(HX711_SCK, LOW);
  51.                 delayMicroseconds(1);
  52.                   if(digitalRead(HX711_DT))
  53.                         count++;
  54.         }
  55.         digitalWrite(HX711_SCK, HIGH);
  56.         count ^= 0x800000;
  57.         delayMicroseconds(1);
  58.         digitalWrite(HX711_SCK, LOW);
  59.         delayMicroseconds(1);
  60.        
  61.         return(count);
  62. }
复制代码

所有资料51hei提供下载:
HX711_AD.zip (1.59 KB, 下载次数: 103)




作者: 大猫8888    时间: 2019-6-28 11:34
感谢

作者: jt110112119    时间: 2021-3-20 11:00
thanks all
作者: at58999    时间: 2022-3-21 22:11
大猫8888 发表于 2019-6-28 11:34
感谢

这个能用吗




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1