0
0

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.

Processing / ControlP5 > serialPlotter (v0.3, v0.4) > String split()使用 / for文でのシリーズ処理の準備

Last updated at Posted at 2016-07-26
動作環境
Processing 3.1.1 on Windows 8.1 pro(64bit)
Library: ControlP5 v2.2.6
Library: Serial

http://qiita.com/7of9/items/9553a7c5d1bd8a295faa
の続き。

code v0.4

v0.4 @ github

以下を実装した。

  • v0.3
    • String split()を使用して、受信文字列のparsing
  • v0.4
    • シリーズの処理をfor文でまとめるための変更 (途中)

動作そのものはv0.2と変化なし。

String splitを使うことでずいぶんすっきりできた。

void serialEvent(Serial myPort) {
  String mystr = myPort.readStringUntil('\n');
  mystr = trim(mystr);
  println(mystr);
    
  String wrk;
  for(int si = 0; si < maxnumSeries; si++) { // si: series index
    wrk = mystr.split("\\s+")[si];
    if (wrk.length() > 0) {
      datamatrix[si][numSeriesData[si]] = float(wrk);
      numSeriesData[si]++;
    }
  }
}

マトリックスのインデックス指定に[si][numSeriesData[si]]には違和感がある。
numSeriesData[si]を一時変数に置くかどうか。

code改良版

shiracamusさんの改良コメント
を参照ください。

0
0
5

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?