代码拉取完成,页面将自动刷新
/*!
* @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);
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。