SunFounder PiDog Kit, Release 1.0
(continued from previous page)
'boom'
, front_color
=
'red'
, brightness
=
0.8
, delay
=
0.001
)
my_dog
.
do_action(
'backward'
, step_count
=
1
, speed
=
98
)
my_dog
.
wait_all_done()
lean_forward()
while
len
(my_dog
.
legs_action_buffer)
>
0
:
sleep(
0.1
)
my_dog
.
do_action(
'stand'
, step_count
=
1
, speed
=
90
)
sleep(
0.5
)
else
:
my_dog
.
rgb_strip
.
set_mode(
'breath'
, front_color
=
'pink'
, brightness
=
0.8
, delay
=
0.08
)
# relax
if
my_dog
.
dual_touch
.
is_slide()
!=
'N'
:
if
len
(my_dog
.
head_action_buffer)
<
2
:
head_nod(
1
)
my_dog
.
do_action(
'wag_tail'
, step_count
=
20
, speed
=
100
)
my_dog
.
rgb_strip
.
set_mode(
'breath'
, front_color
=
'pink'
, brightness
=
0.8
, delay
=
0.08
)
else
:
my_dog
.
tail_stop()
sleep(
0.2
)
if
__name__
==
"__main__"
:
try
:
alert()
except
KeyboardInterrupt
:
my_dog
.
close()
2.2.6 Rest
PiDog will doze off on the ground, and when it hears sounds around it, it will stand up in confusion to see who woke
it up.
Run the Code
cd
/
home
/
pi
/
pidog
/
examples
sudo python3
5
_rest
.
py
After the program runs, PiDog will get down on the ground, shake its head and tail as if dozing off. At the same time,
its sound direction sensor module is working. If PiDog hears noise, it will stand up, look around, and then make a
confused look. Then it’ll doze off again.
Code
Note:
You can
Modify/Reset/Copy/Run/Stop
the code below. But before that, you need to go to source code path
like
pidog\examples
. After modifying the code, you can run it directly to see the effect.
#!/usr/bin/env python3
from
pidog
import
Pidog
from
time
import
sleep
from
preset_actions
import
shake_head
(continues on next page)
54
Chapter 2. Play with Python
Содержание PiDog
Страница 1: ...SunFounder PiDog Kit Release 1 0 sunfounder Jan 09 2023 ...
Страница 2: ......
Страница 4: ...ii ...
Страница 6: ...SunFounder PiDog Kit Release 1 0 Content 2 CONTENTS ...
Страница 8: ...SunFounder PiDog Kit Release 1 0 4 Chapter 1 Component List and Assembly Instructions ...
Страница 15: ...SunFounder PiDog Kit Release 1 0 Step 7 Click the WRITE button 2 1 Quick Guide on Python 11 ...
Страница 92: ...SunFounder PiDog Kit Release 1 0 88 Chapter 2 Play with Python ...
Страница 108: ...SunFounder PiDog Kit Release 1 0 104 Chapter 4 Appendix ...