回答編集履歴

4

X軸

2023/06/02 22:04

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -89,16 +89,16 @@
89
89
 
90
90
  textAlign(CENTER);
91
91
  text("now", Width, Height * 1.08);
92
- j = 0;
92
+ j = -30;
93
93
  for (int i = 0; i <= 5; i++) {
94
94
  text(j, Width / 6 * i, Height * 1.08);
95
- j = j + 5;
95
+ j += 5;
96
96
  }
97
97
  text("time [s]", Width / 2, Height * 1.2);
98
98
 
99
99
  pushMatrix();
100
100
  translate(0, Height / 2);
101
-
101
+
102
102
  PlotData[299] = data;
103
103
  //for (int i = 0; i < 300 - 1; i++) {
104
104
  // PlotData[i] = PlotData[i + 1];
@@ -131,8 +131,9 @@
131
131
  //PlotData[299] = data;
132
132
  }
133
133
  }
134
+ }
134
135
  ```
135
- ![アプリ画像](https://ddjkaamml8q8x.cloudfront.net/questions/2023-06-03/249d1f6d-9f5e-473a-a807-4350556d783b.png)
136
+ ![アプリ画像](https://ddjkaamml8q8x.cloudfront.net/questions/2023-06-03/9395dbb1-9776-4ddc-85b3-ba110d1375da.png)
136
137
 
137
138
  ---
138
139
 

3

マイナス

2023/06/02 21:54

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -50,7 +50,7 @@
50
50
  data = int(map(data, 300, -300, 90, -90));
51
51
 
52
52
  // XYオフセットを適当に入れる
53
- TimeHistory(50, 50, "ECG[deg]", data); // なぜかY軸が逆なので 【マイナス】data
53
+ TimeHistory(50, 50, "ECG[deg]", -data); // なぜかY軸が逆なので 【マイナス】data
54
54
  }
55
55
 
56
56
  void TimeHistory(int positionX, int positionY, String name, int data) {

2

serialEvent

2023/06/02 21:52

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -114,15 +114,23 @@
114
114
  popMatrix();
115
115
  }
116
116
 
117
- //void serialEvent(Serial port) {
117
+ void serialEvent(Serial port) {
118
- // if (port.available() >= 3) {
118
+ if (port.available() >= 3) {
119
- // if (port.read() == 'H') {
119
+ if (port.read() == 'H') {
120
- // int high = port.read();
120
+ int high = port.read();
121
- // int low = port.read();
121
+ int low = port.read();
122
+
123
+ // ローカル変数じゃダメ
122
- // data = high * 256 + low;
124
+ //int data = high * 256 + low;
125
+ data = high * 256 + low;
126
+
123
- // }
127
+ // TimeHistory内でやってる
128
+ //for (int i = 0; i < 300 - 1; i++) {
124
- // }
129
+ // PlotData[i] = PlotData[i + 1];
125
- //}
130
+ //}
131
+ //PlotData[299] = data;
132
+ }
133
+ }
126
134
  ```
127
135
  ![アプリ画像](https://ddjkaamml8q8x.cloudfront.net/questions/2023-06-03/249d1f6d-9f5e-473a-a807-4350556d783b.png)
128
136
 

1

2重コピーしてた

2023/06/02 21:45

投稿

TN8001
TN8001

スコア9350

test CHANGED
@@ -42,22 +42,15 @@
42
42
  void draw() {
43
43
  background(0);
44
44
 
45
- //for (int i = 0; i < 300 - 1; i++) {
46
- // PlotData[i] = PlotData[i + 1];
47
- //}
48
- // ↑↓同じ意味(まとめて移動したほうが早いはず)
49
- arrayCopy(PlotData, 1, PlotData, 0, PlotData.length - 1);
50
-
51
45
  // ダミーデータ(300 ~ -300)
52
46
  data = int(noise(frameCount * 0.05) * 600 - 300);
53
47
  println(data);
54
48
 
55
49
  // グラフ描画が90 ~ -90固定なので、90 ~ -90に圧縮
56
50
  data = int(map(data, 300, -300, 90, -90));
57
- PlotData[299] = data;
58
51
 
59
52
  // XYオフセットを適当に入れる
60
- TimeHistory(50, 50, "ECG[deg]", -data); // なぜかY軸が逆なので 【マイナス】data
53
+ TimeHistory(50, 50, "ECG[deg]", data); // なぜかY軸が逆なので 【マイナス】data
61
54
  }
62
55
 
63
56
  void TimeHistory(int positionX, int positionY, String name, int data) {
@@ -105,10 +98,14 @@
105
98
 
106
99
  pushMatrix();
107
100
  translate(0, Height / 2);
101
+
108
102
  PlotData[299] = data;
109
- for (int i = 0; i < 300 - 1; i++) {
103
+ //for (int i = 0; i < 300 - 1; i++) {
110
- PlotData[i] = PlotData[i + 1];
104
+ // PlotData[i] = PlotData[i + 1];
111
- }
105
+ //}
106
+ // ↑↓同じ意味(まとめて移動したほうが早いはず)
107
+ arrayCopy(PlotData, 1, PlotData, 0, PlotData.length - 1);
108
+
112
109
  for (int i = 0; i < 300 - 1; i++) {
113
110
  stroke(255, 0, 0);
114
111
  line(Width / 300 * i, Height / 6 * PlotData[i] / 30, Width / 300 * (i + 1), Height / 6 * PlotData[i + 1] / 30);
@@ -122,18 +119,12 @@
122
119
  // if (port.read() == 'H') {
123
120
  // int high = port.read();
124
121
  // int low = port.read();
125
- // int data = high * 256 + low;
122
+ // data = high * 256 + low;
126
-
127
- // //for (int i = 0; i < 300 - 1; i++) {
128
- // // PlotData[i] = PlotData[i + 1];
129
- // //}
130
- // arrayCopy(PlotData, 1, PlotData, 0, PlotData.length - 1);
131
- // PlotData[299] = data;
132
123
  // }
133
124
  // }
134
125
  //}
135
126
  ```
136
- ![アプリ画像](https://ddjkaamml8q8x.cloudfront.net/questions/2023-06-03/4da0aa1f-be14-4747-bec6-0fd1f2da9bda.png)
127
+ ![アプリ画像](https://ddjkaamml8q8x.cloudfront.net/questions/2023-06-03/249d1f6d-9f5e-473a-a807-4350556d783b.png)
137
128
 
138
129
  ---
139
130