1 Star 0 Fork 0

DFRobot/DFRobot_PCF8591

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
DFRobot_PCF8591.cpp 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
black5heep 提交于 2018-10-08 18:08 +08:00 . DFRobot_PCF8591 for automatic watering system
/*!
* @file DFRobot_PCF8591.h
* @brief Read PCF8591's data of 4 ADC channel
* @n
*
* @copyright [DFRobot](http://www.dfrobot.com), 2017
* @copyright GNU Lesser General Public License
* @author [DFRobot]
* @version V1.0
* @date 2017-12-22
* @https://github.com/DFRobot/DFRobot_PCF8591
*/
#include <DFRobot_PCF8591.h>
#include "Wire.h"
/**
* @param addr: i2c address
*/
void DFRobot_PCF8591::init(uint8_t addr) {
_i2caddr = addr;
Wire.begin();
/*PCF8591's ADC sampling frequency is related to i2c frequency, 10K in default is too high*/
Wire.setClock(50000);
}
/**
* Read one specified channel
* @param channel [0 - 3]
* @param readType
* SINGLE_ENDED_INPUT
* TREE_DIFFERENTIAL_INPUT
* TWO_SINGLE_ONE_DIFFERENTIAL_INPUT
* TWO_DIFFERENTIAL_INPUT
* @return
*/
uint8_t DFRobot_PCF8591::analogRead(uint8_t channel,uint8_t readType) {
if (channel > 3)
return 0;
uint8_t retValue=0;
// read the current channel
Wire.beginTransmission(_i2caddr);
Wire.write(readType | channel);
Wire.endTransmission();
Wire.requestFrom(_i2caddr, 3);
//the first 2 bytes are the data of last ADC sampling
Wire.read();
Wire.read();
retValue=Wire.read();
return (retValue);
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/dfrobot/DFRobot_PCF8591.git
git@gitee.com:dfrobot/DFRobot_PCF8591.git
dfrobot
DFRobot_PCF8591
DFRobot_PCF8591
master

搜索帮助