1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Serialを引数で渡す

1
Posted at

何をしたいか

Arduinoで開発可能な複数のUART通信ができるマイコンボードにて、
UART通信処理をする関数へ使用するシリアルを渡したい。

動作確認環境

・Arduino IDE 1.8.5
・ESP32 DEVKIT

予備知識

SerialSerial1HardwareSerialという型らしい

コード

シリアルモニタに文字がでてくればOK!
※色分けの為拡張子は「.c」にしていますが、実際は「.ino」です。

SerialTest.c
/*================================================
 * Create:    2018.09.22 teppei 
 * Overview:  HardWareSerialを引数で渡せるかのテスト
 ================================================*/
 
void setup() {
  Serial.begin(115200);
}

void loop() {

  for(int i=40; i<100; i++)
  {
    SerialWrite(Serial, i);
    delay(500);
  }
  
}

void SerialWrite(HardwareSerial &serial, int val)
{
  serial.print("function out: ");
  serial.write(val);
  serial.println();
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?