質問編集履歴
1
コードの記入
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,245 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
とりあえずは入力されるまでサーボが動かないコードを知りたいのでわかるかたいれば教えてください。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
import RPi.GPIO as GPIO
|
22
|
+
|
23
|
+
import time
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
# 1サイクル自動化サブルーチンコード
|
28
|
+
|
29
|
+
GPIO.setmode(GPIO.BCM)
|
30
|
+
|
31
|
+
gp_out = 2
|
32
|
+
|
33
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
34
|
+
|
35
|
+
servo = GPIO.PWM(gp_out, 50)
|
36
|
+
|
37
|
+
servo.start(0.0)
|
38
|
+
|
39
|
+
servo.ChangeDutyCycle(2.0)
|
40
|
+
|
41
|
+
time.sleep(1)
|
42
|
+
|
43
|
+
GPIO.cleanup()
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
GPIO.setmode(GPIO.BCM)
|
52
|
+
|
53
|
+
gp_out = 4
|
54
|
+
|
55
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
56
|
+
|
57
|
+
servo = GPIO.PWM(gp_out, 50)
|
58
|
+
|
59
|
+
servo.start(0.0)
|
60
|
+
|
61
|
+
servo.ChangeDutyCycle(6.5)
|
62
|
+
|
63
|
+
time.sleep(1)
|
64
|
+
|
65
|
+
GPIO.cleanup()
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
GPIO.setmode(GPIO.BCM)
|
70
|
+
|
71
|
+
gp_out = 2
|
72
|
+
|
73
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
74
|
+
|
75
|
+
servo = GPIO.PWM(gp_out, 50)
|
76
|
+
|
77
|
+
servo.start(0.0)
|
78
|
+
|
79
|
+
servo.ChangeDutyCycle(6.0)
|
80
|
+
|
81
|
+
time.sleep(1)
|
82
|
+
|
83
|
+
GPIO.cleanup()
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
GPIO.setmode(GPIO.BCM)
|
88
|
+
|
89
|
+
gp_out = 4
|
90
|
+
|
91
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
92
|
+
|
93
|
+
servo = GPIO.PWM(gp_out, 50)
|
94
|
+
|
95
|
+
servo.start(5.0)
|
96
|
+
|
97
|
+
time.sleep(1)
|
98
|
+
|
99
|
+
servo.ChangeDutyCycle(0.0)
|
100
|
+
|
101
|
+
time.sleep(1)
|
102
|
+
|
103
|
+
GPIO.cleanup()
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
GPIO.setmode(GPIO.BCM)
|
108
|
+
|
109
|
+
gp_out = 3
|
110
|
+
|
111
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
112
|
+
|
113
|
+
servo = GPIO.PWM(gp_out, 50)
|
114
|
+
|
115
|
+
servo.start(0.0)
|
116
|
+
|
117
|
+
servo.ChangeDutyCycle(4.9)
|
118
|
+
|
119
|
+
time.sleep(1)
|
120
|
+
|
121
|
+
GPIO.cleanup()
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
GPIO.setmode(GPIO.BCM)
|
126
|
+
|
127
|
+
gp_out = 14
|
128
|
+
|
129
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
130
|
+
|
131
|
+
servo = GPIO.PWM(gp_out, 50)
|
132
|
+
|
133
|
+
servo.start(0.0)
|
134
|
+
|
135
|
+
servo.ChangeDutyCycle(11.0)
|
136
|
+
|
137
|
+
time.sleep(1)
|
138
|
+
|
139
|
+
GPIO.cleanup()
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
GPIO.setmode(GPIO.BCM)
|
144
|
+
|
145
|
+
gp_out = 4
|
146
|
+
|
147
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
148
|
+
|
149
|
+
servo = GPIO.PWM(gp_out, 50)
|
150
|
+
|
151
|
+
servo.start(0.0)
|
152
|
+
|
153
|
+
time.sleep(2)
|
154
|
+
|
155
|
+
servo.ChangeDutyCycle(7.3)
|
156
|
+
|
157
|
+
time.sleep(1)
|
158
|
+
|
159
|
+
GPIO.cleanup()
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
GPIO.setmode(GPIO.BCM)
|
164
|
+
|
165
|
+
gp_out = 2
|
166
|
+
|
167
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
168
|
+
|
169
|
+
servo = GPIO.PWM(gp_out, 50)
|
170
|
+
|
171
|
+
servo.start(0.0)
|
172
|
+
|
173
|
+
servo.ChangeDutyCycle(2.5)
|
174
|
+
|
175
|
+
time.sleep(2)
|
176
|
+
|
177
|
+
GPIO.cleanup()
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
GPIO.setmode(GPIO.BCM)
|
182
|
+
|
183
|
+
gp_out = 4
|
184
|
+
|
185
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
186
|
+
|
187
|
+
servo = GPIO.PWM(gp_out, 50)
|
188
|
+
|
189
|
+
servo.start(4.0)
|
190
|
+
|
191
|
+
time.sleep(2)
|
192
|
+
|
193
|
+
servo.ChangeDutyCycle(7.5)
|
194
|
+
|
195
|
+
time.sleep(0.03)
|
196
|
+
|
197
|
+
GPIO.cleanup()
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
GPIO.setmode(GPIO.BCM)
|
202
|
+
|
203
|
+
gp_out = 3
|
204
|
+
|
205
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
206
|
+
|
207
|
+
servo = GPIO.PWM(gp_out, 50)
|
208
|
+
|
209
|
+
servo.start(0.2)
|
210
|
+
|
211
|
+
time.sleep(2)
|
212
|
+
|
213
|
+
servo.ChangeDutyCycle(2.5)
|
214
|
+
|
215
|
+
time.sleep(2)
|
216
|
+
|
217
|
+
GPIO.cleanup()
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
GPIO.setmode(GPIO.BCM)
|
222
|
+
|
223
|
+
gp_out = 14
|
224
|
+
|
225
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
226
|
+
|
227
|
+
servo = GPIO.PWM(gp_out, 50)
|
228
|
+
|
229
|
+
servo.start(0.0)
|
230
|
+
|
231
|
+
servo.ChangeDutyCycle(5.2)
|
232
|
+
|
233
|
+
time.sleep(2)
|
234
|
+
|
235
|
+
GPIO.cleanup()
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
GPIO.setmode(GPIO.BCM)
|
242
|
+
|
243
|
+
gp_out = 2
|
244
|
+
|
245
|
+
GPIO.setup(gp_out, GPIO.OUT)
|
246
|
+
|
247
|
+
servo = GPIO.PWM(gp_out, 50)
|
248
|
+
|
249
|
+
servo.start(0.0)
|
250
|
+
|
251
|
+
servo.ChangeDutyCycle(6.0)
|
252
|
+
|
253
|
+
time.sleep(2)
|
254
|
+
|
255
|
+
GPIO.cleanup()
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
今、RUNを押した瞬間から1サイクル自動で動いてしまうので、とりあえずは入力の検知がONされてはじめて動くコードを知りたいのです。
|