質問編集履歴

1

コード全体を載せました

2022/01/01 08:36

投稿

morita05041984
morita05041984

スコア3

test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,243 @@
25
25
 
26
26
 
27
27
  よろしくお願いいたします。
28
+
29
+
30
+
31
+ コード全体を表示します。行っていることは、ラズパイでLチカです。
32
+
33
+ LED点灯後指定した時間で消灯させたいです。
34
+
35
+
36
+
37
+ ```py
38
+
39
+ import webiopi
40
+
41
+ import RPi.GPIO as GPIO
42
+
43
+ from time import sleep
44
+
45
+
46
+
47
+ GPIO = webiopi.GPIO
48
+
49
+
50
+
51
+ LIGHT = 17 # GPIO pin using BCM numbering
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+ # setup function is automatically called at WebIOPi startup
60
+
61
+ def setup():
62
+
63
+ # set the GPIO used by the light to output
64
+
65
+ GPIO.setFunction(LIGHT, GPIO.OUT)
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+ # loop function is repeatedly called by WebIOPi
74
+
75
+ def loop():
76
+
77
+ # gives CPU some time before looping again
78
+
79
+ GPIO.output(17, GPIO.HIGH)
80
+
81
+ sleep(10)
82
+
83
+ GPIO.output(17, GPIO.LOW)
84
+
85
+ sleep(0)
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+ # destroy function is called at WebIOPi shutdown
94
+
95
+ def destroy():
96
+
97
+ GPIO.digitalWrite(LIGHT, GPIO.LOW)
98
+
99
+ ```
100
+
101
+
102
+
103
+ ```HTML
104
+
105
+ <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
106
+
107
+ <html>
108
+
109
+ <head>
110
+
111
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
112
+
113
+ <title>WebIOPi | Light Control</title>
114
+
115
+ <script type="text/javascript" src="/webiopi.js"></script>
116
+
117
+ <script type="text/javascript">
118
+
119
+ webiopi().ready(function() {
120
+
121
+ // Create a "Light" labeled button for GPIO 17
122
+
123
+ var button = webiopi().createGPIOButton(17, "Light");
124
+
125
+ var button_2 = webiopi().createGPIOButton(4, "Light");
126
+
127
+
128
+
129
+
130
+
131
+ // Append button to HTML element with ID="controls" using jQuery
132
+
133
+ $("#controls").append(button);
134
+
135
+ $("#controls_2").append(button_2);
136
+
137
+
138
+
139
+ // Refresh GPIO buttons
140
+
141
+ // pass true to refresh repeatedly of false to refresh once
142
+
143
+ webiopi().refreshGPIO(true);
144
+
145
+ });
146
+
147
+
148
+
149
+ </script>
150
+
151
+
152
+
153
+ <style type="text/css">
154
+
155
+ button {
156
+
157
+ display: block;
158
+
159
+ margin: 5px 5px 5px 5px;
160
+
161
+ width: 160px;
162
+
163
+ height: 45px;
164
+
165
+ font-size: 24pt;
166
+
167
+ font-weight: bold;
168
+
169
+ color: white;
170
+
171
+ }
172
+
173
+
174
+
175
+ button_2 {
176
+
177
+ display: block;
178
+
179
+ margin: 5px 5px 5px 5px;
180
+
181
+ width: 160px;
182
+
183
+ height: 45px;
184
+
185
+ font-size: 24pt;
186
+
187
+ font-weight: bold;
188
+
189
+ color: white;
190
+
191
+ }
192
+
193
+
194
+
195
+
196
+
197
+
198
+
199
+ #gpio17.LOW {
200
+
201
+ background-color: Black;
202
+
203
+ }
204
+
205
+
206
+
207
+ #gpio17.HIGH {
208
+
209
+ background-color: Blue;
210
+
211
+ }
212
+
213
+
214
+
215
+
216
+
217
+ #gpio4.LOW {
218
+
219
+ background-color: Black;
220
+
221
+ }
222
+
223
+
224
+
225
+ #gpio4.HIGH {
226
+
227
+ background-color: Blue;
228
+
229
+ }
230
+
231
+
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+ </style>
246
+
247
+
248
+
249
+ </head>
250
+
251
+ <body>
252
+
253
+
254
+
255
+ <div id="controls" align="center"></div>
256
+
257
+ <div id="controls_2" align="center"></div>
258
+
259
+
260
+
261
+ </body>
262
+
263
+ </html>
264
+
265
+ ```
266
+
267
+ よろしくお願いいたします。