SunFounder pisloth
(continued from previous page)
time.sleep(0.5)
sloth.do_action('stand', 1,95)
time.sleep(0.5)
sloth.do_action('turn left',7,90)
sloth.do_action('stand', 1,95)
time.sleep(0.2)
else :
sloth.do_action('forward', 1,90)
Note: You can add different sound effects or music to musics or sounds folder via Filezilla Software.
4.5 Don’t Touch Me
If you don’t meet PiSloth’s needs, it will get angry and stay away from your touch.
Run the Code
cd /home/pi/pisloth/examples
sudo python3 dont_touch_me.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 Music
from robot_hat import Ultrasonic
from robot_hat import Pin
import time
import os
music = Music()
sloth = Sloth([1,2,3,4])
sloth.set_offset([0,0,0,0])
sonar = Ultrasonic(Pin("D2") ,Pin("D3"))
alert_distance = 20
def main():
distance = sonar.read()
print(distance)
if distance <= alert_distance :
try:
music.sound_effect_threading('./sounds/talk3.wav')
except Exception as e:
print(e)
sloth.do_action('backward', 2, 90)
else:
(continues on next page)
4.5. Don’t Touch Me 85