Arduino在定义语句之间切换
Arduino switch between define statements
我配置了三个串行端口。
我想将功能的输出切换到这三个端口中的任何一个。
端口有#define
语句以给他们友好的名称
#define Port0 Serial
#define Port1 Serial1
#define Port2 Serial2
String destination_select;
我正在尝试做类似的事情:
void port_select(int selectPORT){
if (selectPORT == 0){
destination_select = PORT0;
}
else if (selectPORT == 1){
destination_select = PORT1;
}
else if (selectPORT == 2){
destination_select = PORT2;
}
}
void mycommand(){
port_select(0);
// Prints to Port 0
destination_select.println("Port0");
port_select(1);
// Prints to Port 1
destination_select.println("Port1");
port_select(2);
// Prints to Port 2
destination_select.println("Port2");
}
这不起作用,但我不知道如何使其起作用。
ok
答案是使用指针:
我在这里找到答案:
http://playground.arduino.cc/code/pointer
我希望这对别人有帮助。
相关文章:
- C++ if 语句将条件设置为 true 和循环中的 OR-ing 条件之间的行为差异
- 这两个类语句之间有什么区别?
- switch 语句结束和下一条语句之间的时间是否具有确定性(与路径无关)
- 将 OR 放入 if 语句会导致 ISO C++禁止指针和整数之间的比较(f 允许)
- Arduino在定义语句之间切换
- 将全局声明为类声明语句的一部分与使用单独的语句声明全局之间是否有区别
- 如果 2 个数字之间的差值在 1 到 100 之间,则应运行 if 语句
- 编译器之间在丢弃的 if constexpr(false) 语句中实例化模板的行为不一致
- C++ 中的以下类似语句之间有区别吗?
- 两个语句执行之间的时间差不一致
- 解释 c++ 中语句和表达式之间的区别
- 在 cout 语句之间暂停一段时间
- 我的代码试图找到 0 - n 个数字之间的所有素数,语句"bool prime[n + 1];"中的'+ 1'有什么用?
- 找出.h文件之间的#define语句冲突
- 可以在synchronize with语句之间进行复制省略
- 通过分支语句编写循环和普通循环之间的区别是什么?
- 在return语句中return和表达式之间是否有一个序列点?
- 这两个向量语句之间的区别是什么
- 如何在C++中的正整数和负整数之间计算IF语句中的bool
- 在模板化代码和非模板化代码之间进行接口时替换switch语句