Arduino在定义语句之间切换

Arduino switch between define statements

本文关键字:之间 语句 定义 Arduino      更新时间:2023-10-16

我配置了三个串行端口。

我想将功能的输出切换到这三个端口中的任何一个。

端口有#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

我希望这对别人有帮助。