
Piarm, Release 1.0
(continued from previous page)
if
flag
==
True
:
t
.
say(
"game start"
)
sleep(
60
)
t
.
say(
"three"
)
sleep(
1
)
t
.
say(
"two"
)
sleep(
1
)
t
.
say(
"one"
)
sleep(
1
)
t
.
say(
"game over"
)
flag
=
False
This
timing()
function is used for timing. After prompting the game to start, the game is timed for 60 seconds,
then a countdown of 3, 2, 1 is performed before the game is prompted to end and the
flag
is set to
False
.
def
say_shape
():
k
=
random
.
randint(
1
,
3
)
if
k
==
1
:
t
.
say(
"Round"
)
if
k
==
2
:
t
.
say(
"Triangle"
)
if
k
==
3
:
t
.
say(
"Square"
)
This
say_shape()
function is to make PiArm say a random shape.
if
__name__
==
"__main__"
:
(manual1)
thread1
=
threading
.
Thread(target
=
timing)
thread1
.
start()
while
True
:
key
=
readchar()
.
lower()
if
key
==
'p'
:
(manual2)
flag
=
True
sleep(
3
)
say_shape()
if
flag
==
True
:
control(key)
if
key
==
chr
(
27
):
break
(
"press ctrl+c to quit"
)
This is the main flow of the code.
• Print out the key prompt in the terminal and let
timing()
run in a separate thread.
• Call the
readchar()
function to read the key value.
• If key
p
is read as being pressed, print out the key prompt and let
flag
be
True
, at which point the
timing()
function starts timing, and after 3 seconds, call the
say_shape()
function to make PiArm say a random shape.
• If
flag
is
True
, call the
control()
function to make the PiArm rotate according to the key value.
•
chr(27)
represents the
Esc
key, and if the
Esc
key is pressed, exit the main loop. This step is because
the
readchar()
function is used to read the keyboard all the time, so you can’t stop the code directly with
4.9. GAME - Iron Collection
141
Содержание PiArm
Страница 1: ...Piarm Release 1 0 www sunfounder com Mar 31 2022 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...Piarm Release 1 0 2 CONTENTS ...
Страница 8: ...Piarm Release 1 0 4 Chapter 1 Component List and Assembly Instructions ...
Страница 13: ...Piarm Release 1 0 Assemble the Shovel Bucket to the end of the PiArm with M2x4 screws 2 2 Shovel Bucket 9 ...
Страница 14: ...Piarm Release 1 0 The Shovel Bucket has a rotation range of 90 60 10 Chapter 2 Hardware Introduction ...
Страница 15: ...Piarm Release 1 0 Use range Can t dig water can be used to dig sand and gravel 2 2 Shovel Bucket 11 ...
Страница 17: ...Piarm Release 1 0 Attach the Hanging Clip to the end of the PiArm with the M2x4 screw 2 3 Hanging Clip 13 ...
Страница 18: ...Piarm Release 1 0 The angle range of the Hanging Clip is 0 90 14 Chapter 2 Hardware Introduction ...
Страница 48: ...Piarm Release 1 0 44 Chapter 3 Play with Ezblock ...
Страница 82: ...Piarm Release 1 0 Step 6 Put the control function into the Forever block 78 Chapter 3 Play with Ezblock ...
Страница 91: ...Piarm Release 1 0 3 9 GAME Iron Collection 87 ...
Страница 92: ...Piarm Release 1 0 88 Chapter 3 Play with Ezblock ...
Страница 99: ...Piarm Release 1 0 Step 7 Click the WRITE button 4 1 Quick Guide on Python 95 ...
Страница 146: ...Piarm Release 1 0 Ctrl C At this point you can stop the code with Ctrl C 142 Chapter 4 Play with Python ...
Страница 148: ...Piarm Release 1 0 Yes then Ok Finish 144 Chapter 5 Appendix ...
Страница 152: ...Piarm Release 1 0 Step 4 Double click the connection just created 148 Chapter 5 Appendix ...
Страница 153: ...Piarm Release 1 0 Step 5 Enter Username pi and Password raspberry by default 5 2 Remote Desktop 149 ...
Страница 154: ...Piarm Release 1 0 Step 6 Now you can see the desktop of the Raspberry Pi 150 Chapter 5 Appendix ...
Страница 160: ...Piarm Release 1 0 156 Chapter 5 Appendix ...
Страница 162: ...Piarm Release 1 0 158 Chapter 6 Thank You ...