質問編集履歴

1

コードを修正いたしました。

2021/09/26 09:51

投稿

wataru.py
wataru.py

スコア7

test CHANGED
File without changes
test CHANGED
@@ -119,3 +119,117 @@
119
119
  break
120
120
 
121
121
  ```
122
+
123
+
124
+
125
+ y_waiwai様、thkana様回答、アドバイス本当にありがとうございました!!!
126
+
127
+ 以下、ご指摘を参考に修正したコードです。
128
+
129
+ 現時点では思ったように動作しております。
130
+
131
+ 改良点などあればお願い致します。
132
+
133
+ ```import machine
134
+
135
+ import utime
136
+
137
+ import random
138
+
139
+
140
+
141
+ led1 = machine.Pin(0,machine.Pin.OUT)
142
+
143
+ led2 = machine.Pin(1,machine.Pin.OUT)
144
+
145
+ led3 = machine.Pin(2,machine.Pin.OUT)
146
+
147
+
148
+
149
+ switch1 = machine.Pin(3,machine.Pin.IN,machine.Pin.PULL_UP)
150
+
151
+ switch2 = machine.Pin(4,machine.Pin.IN,machine.Pin.PULL_UP)
152
+
153
+ switch3 = machine.Pin(5,machine.Pin.IN,machine.Pin.PULL_UP)
154
+
155
+
156
+
157
+ score = 0
158
+
159
+
160
+
161
+ flag = False
162
+
163
+
164
+
165
+ ledlist = [led1,led2,led3]
166
+
167
+
168
+
169
+
170
+
171
+
172
+
173
+
174
+
175
+ while True:
176
+
177
+ i = random.randint(0,2)
178
+
179
+ x = ledlist[i]
180
+
181
+
182
+
183
+ x.value(1)
184
+
185
+ for n in range(100):
186
+
187
+ utime.sleep(0.01)
188
+
189
+
190
+
191
+ if (led1.value() == 1):
192
+
193
+ if (switch1.value() == 0 ):
194
+
195
+ flag = True
196
+
197
+
198
+
199
+ if (led2.value() == 1):
200
+
201
+ if (switch2.value() == 0 ):
202
+
203
+ flag = True
204
+
205
+
206
+
207
+ if (led3.value() == 1):
208
+
209
+ if (switch3.value() == 0 ):
210
+
211
+ flag = True
212
+
213
+
214
+
215
+ x.value(0)
216
+
217
+ utime.sleep(1)
218
+
219
+ if (flag == True):
220
+
221
+ score += 1
222
+
223
+ flag = False
224
+
225
+ print(score)
226
+
227
+
228
+
229
+ if (score == 3):
230
+
231
+ break
232
+
233
+
234
+
235
+ ```