feat: 全量同步 254 个常用的 Arduino 扩展库文件
This commit is contained in:
65
arduino-libs/arduino-cli/libraries/Hx711/Hx711.cpp
Normal file
65
arduino-libs/arduino-cli/libraries/Hx711/Hx711.cpp
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Hx711.cpp
|
||||
*
|
||||
* Created on: Oct 31, 2012
|
||||
* Author: agu
|
||||
*/
|
||||
|
||||
#include "Hx711.h"
|
||||
|
||||
Hx711::Hx711(int IO_DOUT,int IO_SCK)
|
||||
{
|
||||
DOUT = IO_DOUT;
|
||||
SCK = IO_SCK;
|
||||
pinMode(SCK, OUTPUT);
|
||||
pinMode(DOUT, INPUT);
|
||||
}
|
||||
|
||||
void Hx711::setScale(float IO_scale)
|
||||
{
|
||||
scale = IO_scale;
|
||||
}
|
||||
|
||||
void Hx711::setOffset(long IO_offset)
|
||||
{
|
||||
offset = IO_offset;
|
||||
}
|
||||
|
||||
long Hx711::getValue()
|
||||
{
|
||||
unsigned long Count;
|
||||
unsigned char i;
|
||||
digitalWrite(SCK,LOW);
|
||||
Count = 0;
|
||||
while(digitalRead(DOUT) == 1);
|
||||
for(i=0;i<24;i++)
|
||||
{
|
||||
digitalWrite(SCK,HIGH);
|
||||
Count = Count<<1;
|
||||
digitalWrite(SCK,LOW);
|
||||
if(digitalRead(DOUT) == 1) Count++;
|
||||
}
|
||||
digitalWrite(SCK,HIGH);
|
||||
Count = Count^0x800000;
|
||||
digitalWrite(SCK,LOW);
|
||||
return Count;
|
||||
}
|
||||
|
||||
long Hx711::getAverageValue(char IO_times)
|
||||
{
|
||||
long sum=0;
|
||||
char i;
|
||||
for(i=0;i<IO_times;i++)
|
||||
{
|
||||
sum += getValue();
|
||||
}
|
||||
return sum/IO_times;
|
||||
}
|
||||
|
||||
float Hx711::getWeight(char IO_times)
|
||||
{
|
||||
long temp;
|
||||
temp = getAverageValue(IO_times) - offset;
|
||||
return (float)temp/scale;
|
||||
}
|
||||
|
||||
38
arduino-libs/arduino-cli/libraries/Hx711/Hx711.h
Normal file
38
arduino-libs/arduino-cli/libraries/Hx711/Hx711.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* Arduino library for digital weight scale of hx711
|
||||
*
|
||||
* hardware design: syyyd
|
||||
* available at http://syyyd.taobao.com
|
||||
*
|
||||
* library design: Weihong Guan (@aguegu)
|
||||
* http://aguegu.net
|
||||
*
|
||||
* library host on
|
||||
* https://github.com/aguegu/Arduino
|
||||
*
|
||||
* Created on: Oct 31, 2012
|
||||
*/
|
||||
|
||||
#ifndef HX711_H_
|
||||
#define HX711_H_
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
class Hx711
|
||||
{
|
||||
private:
|
||||
int DOUT;
|
||||
int SCK;
|
||||
|
||||
float scale;
|
||||
long offset;
|
||||
public:
|
||||
Hx711(int IO_DOUT,int IO_SCK);
|
||||
void setScale(float IO_scale);
|
||||
void setOffset(long IO_offset);
|
||||
|
||||
long getValue();
|
||||
long getAverageValue(char IO_times);
|
||||
float getWeight(char IO_times);
|
||||
};
|
||||
|
||||
#endif /* HX711_H_ */
|
||||
Reference in New Issue
Block a user