SunFounder pisloth
(continued from previous page)
if __name__ == "__main__":
while True:
main()
How it works?
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 Dance project.
Note: You can add different sound effects or music to musics or sounds folder via Filezilla Software.
4.3 Dance
Now, PiSltoh will show you its newly learned dance.
80 Chapter 4. Play with Python