Note
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
Why Join?
Expert Support: Solve post-sale issues and technical challenges with help from our community and team.
Learn & Share: Exchange tips and tutorials to enhance your skills.
Exclusive Previews: Get early access to new product announcements and sneak peeks.
Special Discounts: Enjoy exclusive discounts on our newest products.
Festive Promotions and Giveaways: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [here] and join today!
Custom Action¶
In the previous project, we were able to give PiSloth custom steps, so how do we combine these steps into actions?
For example, have PiSloth make the step from the previous project and then return to the initial position.
Note
You can download and print the PDF Cartoon Mask for your PiSloth.
Step 1: Go to the ~/pisloth/examples path.
cd ~/pisloth/examples
Step 2: Open custom_action.py with the following command.
nano custom_action.py
Step 3: Modify the angle in sloth.add_action(), each group represents a step, and only 2 steps are set here. You can set multiple steps as needed.
sloth.add_action("my_action", [
[ 0,-45 ,0, 40],
[0, 0, 0, 0]
])
Step 4: Run this code.
sudo python3 custom_action.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
import time
sloth = Sloth([1,2,3,4])
sloth.add_action("my_action", [
[ 0,-45 ,0, 40],
[0, 0, 0, 0]
])
def main():
sloth.do_action("my_action", 1, 80)
time.sleep(1)
if __name__ == "__main__":
while True:
main()