質問編集履歴
2
誤字
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
### 該当のソースコード
|
|
13
13
|
|
|
14
|
-
```
|
|
14
|
+
```Processing
|
|
15
15
|
import processing.serial.*;
|
|
16
16
|
PImage img0;
|
|
17
17
|
PImage img1;
|
1
コードの追加
title
CHANGED
|
File without changes
|
body
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
### 前提・実現したいこと
|
|
4
|
+
|
|
1
|
-
Processingでの画像表示にあわせてArduinoにシリアル通信をするプログラムを作成した
|
|
5
|
+
Processingでの画像表示にあわせてArduinoにシリアル通信をするプログラムを作成したい
|
|
6
|
+
問題点が把握できていないので,問題点とアイデアをいただけると助かります.
|
|
7
|
+
|
|
8
|
+
### 発生している問題・エラーメッセージ
|
|
9
|
+
|
|
10
|
+
シリアル通信ができておらず,Arduino側の動作が行われない
|
|
11
|
+
|
|
12
|
+
### 該当のソースコード
|
|
13
|
+
|
|
2
|
-
```
|
|
14
|
+
```Procedding
|
|
3
15
|
import processing.serial.*;
|
|
4
16
|
PImage img0;
|
|
5
17
|
PImage img1;
|
|
18
|
+
float count;
|
|
6
19
|
|
|
7
|
-
|
|
8
20
|
Serial Port;
|
|
9
21
|
|
|
10
22
|
void setup() {
|
|
@@ -13,29 +25,40 @@
|
|
|
13
25
|
Port.bufferUntil(10);
|
|
14
26
|
img0 = loadImage("photo0.png");
|
|
15
27
|
img1 = loadImage("photo1.png");
|
|
16
|
-
|
|
28
|
+
count = 0;
|
|
17
29
|
}
|
|
18
30
|
|
|
19
31
|
void draw(){
|
|
32
|
+
|
|
20
33
|
background(255,255,255);
|
|
21
34
|
|
|
35
|
+
count = count + 0.01;
|
|
36
|
+
|
|
22
|
-
if
|
|
37
|
+
if (count >= 2){
|
|
38
|
+
count = 0;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
int f = floor(count);
|
|
42
|
+
|
|
43
|
+
if (f == 0) {
|
|
23
44
|
Port.write('1');
|
|
45
|
+
image(img1,0,0);
|
|
46
|
+
} else if (f == 1) {
|
|
47
|
+
Port.write('2');
|
|
24
48
|
image(img0,0,0);
|
|
25
49
|
}
|
|
26
|
-
if(mousePressed && (mouseButton == RIGHT)) {
|
|
27
|
-
Port.write('2');
|
|
28
|
-
image(img1,0,0);
|
|
29
|
-
}
|
|
30
50
|
}
|
|
31
51
|
```
|
|
52
|
+
|
|
53
|
+
### 試したこと
|
|
32
|
-
|
|
54
|
+
下記のマウスクリックによる画像表示とシリアル通信を試した場合正常に動作した
|
|
55
|
+
|
|
33
56
|
```Processing
|
|
34
57
|
import processing.serial.*;
|
|
35
58
|
PImage img0;
|
|
36
59
|
PImage img1;
|
|
37
|
-
float count;
|
|
38
60
|
|
|
61
|
+
|
|
39
62
|
Serial Port;
|
|
40
63
|
|
|
41
64
|
void setup() {
|
|
@@ -44,30 +67,74 @@
|
|
|
44
67
|
Port.bufferUntil(10);
|
|
45
68
|
img0 = loadImage("photo0.png");
|
|
46
69
|
img1 = loadImage("photo1.png");
|
|
47
|
-
|
|
70
|
+
|
|
48
71
|
}
|
|
49
72
|
|
|
50
73
|
void draw(){
|
|
51
|
-
|
|
52
74
|
background(255,255,255);
|
|
53
75
|
|
|
76
|
+
if(mousePressed && (mouseButton == LEFT)) {
|
|
54
|
-
|
|
77
|
+
Port.write('1');
|
|
55
|
-
|
|
56
|
-
|
|
78
|
+
image(img0,0,0);
|
|
57
|
-
count = 0;
|
|
58
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);
|
|
59
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
|
+
|
|
60
|
-
|
|
120
|
+
digitalWrite(43, HIGH);
|
|
121
|
+
digitalWrite(45, HIGH);
|
|
122
|
+
digitalWrite(47, HIGH);
|
|
123
|
+
digitalWrite(49, HIGH);
|
|
61
124
|
|
|
62
|
-
if (f == 0) {
|
|
63
|
-
Port.write('1');
|
|
64
|
-
image(img1,0,0);
|
|
65
|
-
|
|
125
|
+
}
|
|
66
|
-
|
|
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);
|
|
67
|
-
|
|
135
|
+
digitalWrite(40, HIGH);
|
|
136
|
+
|
|
137
|
+
}
|
|
68
138
|
}
|
|
69
139
|
}
|
|
70
140
|
```
|
|
71
|
-
こちらでループさせようとしたプログラムではシリアル通信ができていないようです.
|
|
72
|
-
|
|
73
|
-
問題点が把握できていないので,問題点とアイデアをいただけると助かります.
|