質問編集履歴
2
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
### 該当のソースコード
|
13
13
|
|
14
|
-
```Proce
|
14
|
+
```Processing
|
15
15
|
import processing.serial.*;
|
16
16
|
PImage img0;
|
17
17
|
PImage img1;
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,36 +1,17 @@
|
|
1
|
-
Processingでの画像表示にあわせてArduinoにシリアル通信をするプログラムを作成したのですがシリアル通信ができていないようで困っています.
|
2
|
-
```Processing
|
3
|
-
import processing.serial.*;
|
4
|
-
PImage img0;
|
5
|
-
PImage img1;
|
6
1
|
|
7
2
|
|
8
|
-
|
3
|
+
### 前提・実現したいこと
|
9
4
|
|
10
|
-
void setup() {
|
11
|
-
size(1920, 1080);
|
12
|
-
|
5
|
+
Processingでの画像表示にあわせてArduinoにシリアル通信をするプログラムを作成したい
|
13
|
-
Port.bufferUntil(10);
|
14
|
-
|
6
|
+
問題点が把握できていないので,問題点とアイデアをいただけると助かります.
|
15
|
-
img1 = loadImage("photo1.png");
|
16
|
-
|
17
|
-
}
|
18
7
|
|
8
|
+
### 発生している問題・エラーメッセージ
|
9
|
+
|
10
|
+
シリアル通信ができておらず,Arduino側の動作が行われない
|
11
|
+
|
19
|
-
|
12
|
+
### 該当のソースコード
|
20
|
-
|
13
|
+
|
21
|
-
|
22
|
-
if(mousePressed && (mouseButton == LEFT)) {
|
23
|
-
Port.write('1');
|
24
|
-
image(img0,0,0);
|
25
|
-
}
|
26
|
-
if(mousePressed && (mouseButton == RIGHT)) {
|
27
|
-
Port.write('2');
|
28
|
-
image(img1,0,0);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
```
|
32
|
-
こちらのマウスのクリックに合わせて画像表示とシリアル通信を行うプログラムは正常に動作するのですが
|
33
|
-
```Proce
|
14
|
+
```Procedding
|
34
15
|
import processing.serial.*;
|
35
16
|
PImage img0;
|
36
17
|
PImage img1;
|
@@ -68,6 +49,93 @@
|
|
68
49
|
}
|
69
50
|
}
|
70
51
|
```
|
71
|
-
こちらでループさせようとしたプログラムではシリアル通信ができていないようです.
|
72
52
|
|
53
|
+
### 試したこと
|
73
|
-
|
54
|
+
下記のマウスクリックによる画像表示とシリアル通信を試した場合正常に動作した
|
55
|
+
|
56
|
+
```Processing
|
57
|
+
import processing.serial.*;
|
58
|
+
PImage img0;
|
59
|
+
PImage img1;
|
60
|
+
|
61
|
+
|
62
|
+
Serial Port;
|
63
|
+
|
64
|
+
void setup() {
|
65
|
+
size(1920, 1080);
|
66
|
+
Port = new Serial(this, "COM4", 9600);
|
67
|
+
Port.bufferUntil(10);
|
68
|
+
img0 = loadImage("photo0.png");
|
69
|
+
img1 = loadImage("photo1.png");
|
70
|
+
|
71
|
+
}
|
72
|
+
|
73
|
+
void draw(){
|
74
|
+
background(255,255,255);
|
75
|
+
|
76
|
+
if(mousePressed && (mouseButton == LEFT)) {
|
77
|
+
Port.write('1');
|
78
|
+
image(img0,0,0);
|
79
|
+
}
|
80
|
+
if(mousePressed && (mouseButton == RIGHT)) {
|
81
|
+
Port.write('2');
|
82
|
+
image(img1,0,0);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
```
|
86
|
+
|
87
|
+
|
88
|
+
### 補足情報(FW/ツールのバージョンなど)
|
89
|
+
|
90
|
+
Arduino側のコード
|
91
|
+
```
|
92
|
+
void setup()
|
93
|
+
{
|
94
|
+
pinMode(43, OUTPUT);
|
95
|
+
pinMode(45, OUTPUT);
|
96
|
+
pinMode(47, OUTPUT);
|
97
|
+
pinMode(49, OUTPUT);
|
98
|
+
|
99
|
+
pinMode(34, OUTPUT);
|
100
|
+
pinMode(36, OUTPUT);
|
101
|
+
pinMode(38, OUTPUT);
|
102
|
+
pinMode(40, OUTPUT);
|
103
|
+
|
104
|
+
Serial.begin(9600);
|
105
|
+
|
106
|
+
}
|
107
|
+
|
108
|
+
void loop()
|
109
|
+
{
|
110
|
+
if (Serial.available() > 0) {
|
111
|
+
char displayState = Serial.read();
|
112
|
+
|
113
|
+
if(displayState == '1') {
|
114
|
+
|
115
|
+
digitalWrite(34, LOW);
|
116
|
+
digitalWrite(36, LOW);
|
117
|
+
digitalWrite(38, LOW);
|
118
|
+
digitalWrite(40, LOW);
|
119
|
+
|
120
|
+
digitalWrite(43, HIGH);
|
121
|
+
digitalWrite(45, HIGH);
|
122
|
+
digitalWrite(47, HIGH);
|
123
|
+
digitalWrite(49, HIGH);
|
124
|
+
|
125
|
+
}
|
126
|
+
if(displayState == '2') {
|
127
|
+
digitalWrite(43, LOW);
|
128
|
+
digitalWrite(45, LOW);
|
129
|
+
digitalWrite(47, LOW);
|
130
|
+
digitalWrite(49, LOW);
|
131
|
+
|
132
|
+
digitalWrite(34, HIGH);
|
133
|
+
digitalWrite(36, HIGH);
|
134
|
+
digitalWrite(38, HIGH);
|
135
|
+
digitalWrite(40, HIGH);
|
136
|
+
|
137
|
+
}
|
138
|
+
}
|
139
|
+
}
|
140
|
+
```
|
141
|
+
|