質問編集履歴
3
コードが間違えておりましたので修正いたしました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -54,7 +54,7 @@
|
|
54
54
|
|
55
55
|
sleep(1)
|
56
56
|
|
57
|
-
|
57
|
+
GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
58
58
|
|
59
59
|
elif ( COMMAND == "STRONG" ):
|
60
60
|
|
@@ -246,7 +246,7 @@
|
|
246
246
|
|
247
247
|
sleep(1)
|
248
248
|
|
249
|
-
|
249
|
+
GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
250
250
|
|
251
251
|
break
|
252
252
|
|
2
Breakの書き方を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -234,9 +234,25 @@
|
|
234
234
|
|
235
235
|
### 該当のソースコード
|
236
236
|
|
237
|
-
|
237
|
+
python```
|
238
|
+
|
238
|
-
|
239
|
+
コード
|
240
|
+
|
239
|
-
|
241
|
+
def loop():
|
242
|
+
|
243
|
+
if ( COMMAND == "POW" ):
|
244
|
+
|
245
|
+
GPIO.digitalWrite( POW_PIN, GPIO.LOW )
|
246
|
+
|
247
|
+
sleep(1)
|
248
|
+
|
249
|
+
. if GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
250
|
+
|
251
|
+
break
|
252
|
+
|
253
|
+
```
|
254
|
+
|
255
|
+
上記のBreakの書き方だとWeb画面がエラーで表示されなくなります。
|
240
256
|
|
241
257
|
|
242
258
|
|
1
HTMLを追加しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
PYTHONでの動作
|
1
|
+
PYTHONでの動作でループが止まらない
|
test
CHANGED
@@ -1,4 +1,208 @@
|
|
1
|
+
```Python
|
2
|
+
|
3
|
+
①.pyの中身です。
|
4
|
+
|
5
|
+
import time
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
GPIO = webiopi.GPIO
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
POW_PIN = 26
|
14
|
+
|
15
|
+
STRONG_PIN = 13
|
16
|
+
|
17
|
+
MODE_PIN = 19
|
18
|
+
|
19
|
+
WEAK_PIN = 6
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
COMMAND = "reset"
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
def setup():
|
28
|
+
|
29
|
+
GPIO.setFunction( POW_PIN, GPIO.OUT )
|
30
|
+
|
31
|
+
GPIO.setFunction( STRONG_PIN, GPIO.OUT )
|
32
|
+
|
33
|
+
GPIO.setFunction( MODE_PIN, GPIO.OUT )
|
34
|
+
|
35
|
+
GPIO.setFunction( WEAK_PIN, GPIO.OUT )
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
GPIO.digitalWrite( POW_PIN, GPIO.LOW )
|
40
|
+
|
41
|
+
GPIO.digitalWrite( STRONG_PIN, GPIO.LOW )
|
42
|
+
|
43
|
+
GPIO.digitalWrite( MODE_PIN, GPIO.LOW )
|
44
|
+
|
45
|
+
GPIO.digitalWrite( WEAK_PIN, GPIO.LOW )
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
def loop():
|
50
|
+
|
51
|
+
if ( COMMAND == "POW" ):
|
52
|
+
|
53
|
+
GPIO.digitalWrite( POW_PIN, GPIO.LOW )
|
54
|
+
|
55
|
+
sleep(1)
|
56
|
+
|
57
|
+
. if GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
58
|
+
|
59
|
+
elif ( COMMAND == "STRONG" ):
|
60
|
+
|
61
|
+
GPIO.digitalWrite( STRONG_PIN, GPIO.LOW )
|
62
|
+
|
63
|
+
sleep(1)
|
64
|
+
|
65
|
+
GPIO.digitalWrite( LEFT_PIN, GPIO.HIGH )
|
66
|
+
|
67
|
+
elif ( COMMAND == "MODE" ):
|
68
|
+
|
69
|
+
GPIO.digitalWrite( MODE_PIN, GPIO.LOW )
|
70
|
+
|
71
|
+
sleep(1)
|
72
|
+
|
73
|
+
GPIO.digitalWrite( MODE_PIN, GPIO.HIGH )
|
74
|
+
|
75
|
+
elif ( COMMAND == "reset" ):
|
76
|
+
|
77
|
+
GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
78
|
+
|
79
|
+
GPIO.digitalWrite( STRONG_PIN, GPIO.HIGH )
|
80
|
+
|
81
|
+
GPIO.digitalWrite( WEAK_PIN, GPIO.HIGH )
|
82
|
+
|
83
|
+
GPIO.digitalWrite( MODE_PIN, GPIO.HIGH )
|
84
|
+
|
85
|
+
sleep(1)
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
def destroy():
|
90
|
+
|
91
|
+
GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
92
|
+
|
93
|
+
GPIO.digitalWrite( STRONG_PIN, GPIO.HIGH )
|
94
|
+
|
95
|
+
GPIO.digitalWrite( WEAK_PIN, GPIO.HIGH )
|
96
|
+
|
97
|
+
GPIO.digitalWrite( MODE_PIN, GPIO.HIGH )
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
@webiopi.macro
|
102
|
+
|
103
|
+
def command( com ):
|
104
|
+
|
105
|
+
global COMMAND
|
106
|
+
|
107
|
+
if ( com == "1" ):
|
108
|
+
|
109
|
+
COMMAND = "pow"
|
110
|
+
|
111
|
+
elif ( com == "2" ):
|
112
|
+
|
113
|
+
COMMAND = "strong"
|
114
|
+
|
115
|
+
elif ( com == "3" ):
|
116
|
+
|
117
|
+
COMMAND = "weak"
|
118
|
+
|
119
|
+
elif ( com == "0" ):
|
120
|
+
|
121
|
+
COMMAND = "mode"
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
②HTMLです
|
126
|
+
|
127
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
128
|
+
|
129
|
+
<html>
|
130
|
+
|
131
|
+
<head>
|
132
|
+
|
133
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
134
|
+
|
135
|
+
<title>Tank Remote Controller</title>
|
136
|
+
|
137
|
+
<script type="text/javascript" src="/webiopi.js"></script>
|
138
|
+
|
139
|
+
<script type="text/javascript">
|
140
|
+
|
141
|
+
webiopi().ready(function() {
|
142
|
+
|
143
|
+
webiopi().callMacro( "command", 5 );
|
144
|
+
|
145
|
+
});
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
function pushBotton( com ) {
|
150
|
+
|
151
|
+
webiopi().callMacro( "command", com );
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
</script>
|
162
|
+
|
163
|
+
</head>
|
164
|
+
|
165
|
+
<body>
|
166
|
+
|
167
|
+
<h1>コントローラー</h1>
|
168
|
+
|
169
|
+
<table>
|
170
|
+
|
171
|
+
<tr>
|
172
|
+
|
173
|
+
<td> </td>
|
174
|
+
|
175
|
+
<td><input type="button" name="pow" value="電 源" style="font-size:3em;" onclick="pushBotton(1)"></td>
|
176
|
+
|
177
|
+
<td> </td>
|
178
|
+
|
179
|
+
</tr>
|
180
|
+
|
181
|
+
<tr>
|
182
|
+
|
183
|
+
<td><input type="button" name="reset" value="リセット" style="font-size:3em;" onclick="pushBotton(6)"></td>
|
184
|
+
|
185
|
+
<td><input type="button" name="storong" value=" 強 " style="font-size:3em;" onclick="pushBotton(3)"></td>
|
186
|
+
|
187
|
+
<td><input type="button" name="weak" value=" 弱 " style="font-size:3em;" onclick="pushBotton(2)"></td>
|
188
|
+
|
189
|
+
<td><input type="button" name="mode" value="モード" style="font-size:3em;" onclick="pushBotton(0)"></td>
|
190
|
+
|
191
|
+
</tr>
|
192
|
+
|
193
|
+
</table>
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
</body>
|
198
|
+
|
199
|
+
</html>
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
|
204
|
+
|
1
|
-
ラズパイ+PYTHONでWebからの入力でリレーモジュールを稼働させています。
|
205
|
+
```ラズパイ+PYTHONでWebからの入力でリレーモジュールを稼働させています。
|
2
206
|
|
3
207
|
Webからボタン入力はできるのですが一度LOWにしたらすぐにHIGHにしたいので
|
4
208
|
|
@@ -30,126 +234,6 @@
|
|
30
234
|
|
31
235
|
### 該当のソースコード
|
32
236
|
|
33
|
-
import webiopi
|
34
|
-
|
35
|
-
import time
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
GPIO = webiopi.GPIO
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
POW_PIN = 26
|
44
|
-
|
45
|
-
STRONG_PIN = 13
|
46
|
-
|
47
|
-
MODE_PIN = 19
|
48
|
-
|
49
|
-
WEAK_PIN = 6
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
COMMAND = "reset"
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
def setup():
|
58
|
-
|
59
|
-
GPIO.setFunction( POW_PIN, GPIO.OUT )
|
60
|
-
|
61
|
-
GPIO.setFunction( STRONG_PIN, GPIO.OUT )
|
62
|
-
|
63
|
-
GPIO.setFunction( MODE_PIN, GPIO.OUT )
|
64
|
-
|
65
|
-
GPIO.setFunction( WEAK_PIN, GPIO.OUT )
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
GPIO.digitalWrite( POW_PIN, GPIO.LOW )
|
70
|
-
|
71
|
-
GPIO.digitalWrite( STRONG_PIN, GPIO.LOW )
|
72
|
-
|
73
|
-
GPIO.digitalWrite( MODE_PIN, GPIO.LOW )
|
74
|
-
|
75
|
-
GPIO.digitalWrite( WEAK_PIN, GPIO.LOW )
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
def loop():
|
80
|
-
|
81
|
-
if ( COMMAND == "POW" ):
|
82
|
-
|
83
|
-
GPIO.digitalWrite( POW_PIN, GPIO.LOW )
|
84
|
-
|
85
|
-
sleep(1)
|
86
|
-
|
87
|
-
. if GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
88
|
-
|
89
|
-
elif ( COMMAND == "STRONG" ):
|
90
|
-
|
91
|
-
GPIO.digitalWrite( STRONG_PIN, GPIO.LOW )
|
92
|
-
|
93
|
-
sleep(1)
|
94
|
-
|
95
|
-
GPIO.digitalWrite( LEFT_PIN, GPIO.HIGH )
|
96
|
-
|
97
|
-
elif ( COMMAND == "MODE" ):
|
98
|
-
|
99
|
-
GPIO.digitalWrite( MODE_PIN, GPIO.LOW )
|
100
|
-
|
101
|
-
sleep(1)
|
102
|
-
|
103
|
-
GPIO.digitalWrite( MODE_PIN, GPIO.HIGH )
|
104
|
-
|
105
|
-
elif ( COMMAND == "reset" ):
|
106
|
-
|
107
|
-
GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
108
|
-
|
109
|
-
GPIO.digitalWrite( STRONG_PIN, GPIO.HIGH )
|
110
|
-
|
111
|
-
GPIO.digitalWrite( WEAK_PIN, GPIO.HIGH )
|
112
|
-
|
113
|
-
GPIO.digitalWrite( MODE_PIN, GPIO.HIGH )
|
114
|
-
|
115
|
-
sleep(1)
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
def destroy():
|
120
|
-
|
121
|
-
GPIO.digitalWrite( POW_PIN, GPIO.HIGH )
|
122
|
-
|
123
|
-
GPIO.digitalWrite( STRONG_PIN, GPIO.HIGH )
|
124
|
-
|
125
|
-
GPIO.digitalWrite( WEAK_PIN, GPIO.HIGH )
|
126
|
-
|
127
|
-
GPIO.digitalWrite( MODE_PIN, GPIO.HIGH )
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
@webiopi.macro
|
132
|
-
|
133
|
-
def command( com ):
|
134
|
-
|
135
|
-
global COMMAND
|
136
|
-
|
137
|
-
if ( com == "1" ):
|
138
|
-
|
139
|
-
COMMAND = "pow"
|
140
|
-
|
141
|
-
elif ( com == "2" ):
|
142
|
-
|
143
|
-
COMMAND = "strong"
|
144
|
-
|
145
|
-
elif ( com == "3" ):
|
146
|
-
|
147
|
-
COMMAND = "weak"
|
148
|
-
|
149
|
-
elif ( com == "0" ):
|
150
|
-
|
151
|
-
COMMAND = "mode"
|
152
|
-
|
153
237
|
|
154
238
|
|
155
239
|
|