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