SunFounder pisloth
(continued from previous page)
if distance< 0:
continue
if distance<=contact_distance:
break
sloth.do_action('forward', 1,95)
sloth.do_action('stand', 1, 90)
time.sleep(1)
Note: You can add different sound effects or music to musics or sounds folder via Filezilla Software.
4.7 Emotional PiSloth
PiSloth is very emotional, sometimes happy, sometimes shy, sometimes confused.
Run the Code
cd /home/pi/pisloth/examples
sudo python3 emotional_pisloth.py
Code
Note: You can Modify/Reset/Copy/Run/Stop the code below. But before that, you need to go to source code path
like pisloth\examples. After modifying the code, you can run it directly to see the effect.
from pisloth import Sloth
from robot_hat import TTS, Music
import time
tts = TTS()
music = Music()
sloth = Sloth([1,2,3,4])
sloth.set_offset([0,0,0,0])
def confuse():
try:
music.sound_effect_threading('./sounds/sign.wav')
except Exception as e:
print(e)
sloth.do_action('hook', 1, 90)
def happy():
try:
music.sound_effect_threading('./sounds/happy2.wav')
except Exception as e:
print(e)
for i in range(3):
sloth.do_action('hook', 1, 90)
sloth.do_action('stand', 1, 90)
def fear():
(continues on next page)
4.7. Emotional PiSloth 89