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