This is the first project. PiSloth has woken up, and it moves freely.
Run the Code
cd /home/pi/pisloth/examples sudo python3 move.py
After running the code, you will see PiSloth move left 7 steps, forward 5 steps, right 7 steps, and forward 5 steps.
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 sloth = Sloth([1,2,3,4]) sloth.set_offset([0,0,0,0]) def main(): 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) 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 = 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 parameters:
motion_nameis the name of specific actions, including:
moon walk left,
moon walk right,
walk backward boldly,
walk backward shyly,
steprepresents the number of each action is done, the default is 1.
speedindicates the speed of the action, the default is 50 and the range is 0~100.
bpmmeans rhythm, we will use it later in the Dance project.
You can add different sound effects or music to
sounds folder via Filezilla Software.