
SunFounder pisloth
First, import the
Sloth
class from the
pisloth
library you have installed, which contains all of PiSloth’s actions
and the functions that implement them.
from
pisloth
import
Sloth
Then instantiate the
Sloth
class.
sloth
=
Sloth([
1
,
2
,
3
,
4
])
sloth
.
set_offset([
0
,
0
,
0
,
0
])
Finally use the
sloth.do_action()
function to make PiSloth move.
sloth
.
do_action(
'turn left'
,
7
,
90
)
sloth
.
do_action(
'forward'
,
5
,
90
)
sloth
.
do_action(
'turn right'
,
7
,
90
)
sloth
.
do_action(
'forward'
,
5
,
90
)
In general, all actions of PiSloth can be implemented with the
sloth.do_action()
function. It has four parame-
ters:
•
motion_name
is the name of specific actions, including:
forward
,
turn right
,
turn left
,
backward
,
stand
,
moon walk left
,
moon walk right
,
hook
,
big swing
,
swing
,
walk
boldly
,
walk backward boldly
,
walk shyly
,
walk backward shyly
,
stomp rihgt
,
stomp left
,
close
,
open
,
tiptoe left
,
tiptoe right
,
fall left
,
fall right
.
•
step
represents the number of each action is done, the default is 1.
•
speed
indicates the speed of the action, the default is 50 and the range is 0~100.
•
bpm
means rhythm, we will use it later in the
project.
Note:
You can add different sound effects or music to
musics
or
sounds
folder via
4.3 Dance
Now, PiSltoh will show you its newly learned dance.
62
Chapter 4. Play with Python
Summary of Contents for PiSloth
Page 1: ...SunFounder pisloth www sunfounder com Oct 19 2021 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...SunFounder pisloth 2 CONTENTS ...
Page 8: ...SunFounder pisloth 4 Chapter 1 Component List and Assembly Instructions ...
Page 18: ...SunFounder pisloth EXAMPLE 14 Chapter 3 Play with Ezblock ...
Page 20: ...SunFounder pisloth 16 Chapter 3 Play with Ezblock ...
Page 22: ...SunFounder pisloth Confuse Happy 18 Chapter 3 Play with Ezblock ...
Page 23: ...SunFounder pisloth Fear Sad 3 5 Emotional PiSloth 19 ...
Page 25: ...SunFounder pisloth 3 6 Dance Now PiSltoh will show you his newly learned dance 3 6 Dance 21 ...
Page 28: ...SunFounder pisloth 24 Chapter 3 Play with Ezblock ...
Page 32: ...SunFounder pisloth 28 Chapter 3 Play with Ezblock ...
Page 35: ...SunFounder pisloth 3 8 Remote Control 31 ...
Page 39: ...SunFounder pisloth 3 9 Custom Step 35 ...
Page 41: ...SunFounder pisloth The complete code is as follows 3 9 Custom Step 37 ...
Page 50: ...SunFounder pisloth Step 7 Click the WRITE button 46 Chapter 4 Play with Python ...
Page 86: ...SunFounder pisloth 82 Chapter 4 Play with Python ...
Page 90: ...SunFounder pisloth Yes then Ok Finish 86 Chapter 5 Appendix ...
Page 94: ...SunFounder pisloth Step 4 Double click the connection just created 90 Chapter 5 Appendix ...
Page 102: ...SunFounder pisloth 98 Chapter 5 Appendix ...