1 Star 0 Fork 0

上海市虹口区青少年活动中心/Morse-Pjct(摩尔斯码)

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ports.h 2.02 KB
一键复制 编辑 原始数据 按行查看 历史
= 提交于 2020-07-12 12:23 . Bug fix
namespace Ports
{
class Port
{
protected:
int port;
Port(int port)
{
this->port = port;
}
public:
void setPort(int port)
{
this->port = port;
}
};
class ADPort : public Port
{
protected:
bool reversed;
ADPort(int port, bool reversed) : Port(port) { this->reversed = reversed; }
public:
void setReverse(bool reversed)
{
this->reversed = reversed;
}
};
class DIPort : public ADPort
{
public:
DIPort(int port, bool reversed = false) : ADPort(port, reversed) { pinMode(port, INPUT); }
bool get(void)
{
return digitalRead(port) ^ reversed;
}
void setPort(int port)
{
this->port = port;
pinMode(port, INPUT);
}
};
class DOPort : public ADPort
{
public:
DOPort(int port, bool reversed = false) : ADPort(port, reversed) { pinMode(port, OUTPUT); }
void set(bool HoL)
{
digitalWrite(port, HoL ^ reversed);
}
void setPort(int port)
{
this->port = port;
pinMode(port, OUTPUT);
}
};
class AIPort : public ADPort
{
public:
AIPort(int port, bool reversed = false) : ADPort(port, reversed) { pinMode(port, INPUT); }
int get(void)
{
int temp;
temp = analogRead(port);
return reversed ? 255 - temp : temp;
}
void setPort(int port)
{
this->port = port;
pinMode(port, INPUT);
}
};
class AOPort : public ADPort
{
public:
AOPort(int port, bool reversed = false) : ADPort(port, reversed) { pinMode(port, OUTPUT); }
void set(int Lvl)
{
analogWrite(port, reversed ? 255 - Lvl : Lvl);
}
void setPort(int port)
{
this->port = port;
pinMode(port, OUTPUT);
}
};
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Arduino
1
https://gitee.com/HKQQSNHDZX/Morse-Pjct.git
git@gitee.com:HKQQSNHDZX/Morse-Pjct.git
HKQQSNHDZX
Morse-Pjct
Morse-Pjct(摩尔斯码)
master

搜索帮助