1 Star 0 Fork 0

梅花三弄再回首/smbus-cpp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PCF8591_test.cpp 1.24 KB
一键复制 编辑 原始数据 按行查看 历史
梅花三弄再回首 提交于 2024-10-10 00:59 +08:00 . 提交了代码文件
/**
* @file PCF8591_test.cpp
* @brief 对自己写的库进行测试,使用PCF8591
* @author 梅花
* @data 2024年10月9日22:33:00
* @version 0.1
* @copyright 梅花
*/
#include "SMBus.h"
#include <iostream>
long address;
auto bus = SMBus(1);
namespace test{
void setup(int addr)
{
bus.set_pec(1);
bus.set_pec(0);
address = addr;
}
long read(int chn)
{
switch(chn)
{
case 0:
bus.write_byte(address,0x40);
break;
case 1:
bus.write_byte(address,0x41);
break;
case 2:
bus.write_byte(address,0x42);
break;
case 3:
bus.write_byte(address,0x43);
break;
}
bus.read_byte(address); // dummy read to start conversion
return bus.read_byte(address);
}
void write(int val)
{
// print temp to see on terminal else comment out
bus.write_byte_data(address, 0x40, val);
}
} // namespace test
int main(void)
{
using namespace std;
test::setup(0x48);
while(1)
{
cout
<< "AIN0 = " << test::read(0)
<< '\t'
<< "AIN1 = " << test::read(1)
<< endl;
auto tmp = test::read(0);
tmp = tmp*(255-125)/255+125;
test::write(tmp);
sleep(1);
}
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/PlumBlossomMaid/smbus-cpp.git
git@gitee.com:PlumBlossomMaid/smbus-cpp.git
PlumBlossomMaid
smbus-cpp
smbus-cpp
master

搜索帮助