Arduino在define语句之间切换

时间:2017-04-28 15:52:06

标签: c++ arduino

我配置了三个串口。

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

Ports有#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");
}

这不起作用,但我不知道如何使其发挥作用。

1 个答案:

答案 0 :(得分:0)

确定
答案是使用指针:

我在这里找到了答案:

http://playground.arduino.cc/Code/Pointer

我希望这有助于其他人。