
Piarm, Release 1.0
while
True
:
if
leftJoystick
.
read_status()
==
"pressed"
and
rightJoystick
.
read_status()
==
˓
→
"pressed"
:
t
.
say(
"timing begins"
)
game_flag
=
1
if
game_flag
==
1
:
control()
This is the main flow of the code, when the left and right joysticks are pressed at the same time, PiArm says the timer
starts, let
game_flag
be 1, then you can call
control()
function to control PiArm.
4.9 GAME - Iron Collection
In this project, prepare 3 shapes of iron pieces: triangle, circle and square. PiArm will randomly say a shape, and you
need to control PiArm to put the corresponding shape of iron pieces into the corresponding box.
Run the code
cd
/
home
/
pi
/
piarm
/
examples
sudo python3 game_iron_collection
.
py
After the code is run, first press
p
on the keyboard to start the game, PiArm will prompt the game to start, then
randomly say a shape (
Round
,
Triangle
and
Square
). You need to use
w
,
s
,
a
,
d
,
i
and
k
on the keyboard to
control Arm,
j
and
l
to pick up the corresponding shape (you need to install
to PiArm first.).
60 seconds later, the game will be prompted to end and you will no longer be able to control the PiArm. If you want
to stop the code from running, you need to press the
Esc
key first, then press
Ctrl+C
.
Note:
•
w
,
s
,
a
,
d
,
i
and
k
are used to control the rotation of the Arm.
•
j
and
l
are used to control the ON and OFF of the Electromagnet.
Code
from
piarm
import
PiArm
from
robot_hat
import
Pin,PWM,Servo,ADC
from
time
import
time,sleep
from
robot_hat.utils
import
reset_mcu
from
robot_hat
import
TTS
import
threading
import
sys
import
tty
import
termios
import
random
reset_mcu()
sleep(
0.01
)
t
=
TTS()
arm
=
PiArm([
1
,
2
,
3
])
arm
.
electromagnet_init(PWM(
'P3'
))
arm
.
set_offset([
0
,
0
,
0
])
(continues on next page)
138
Chapter 4. Play with Python
Содержание 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 ...