EasyManua.ls Logo

SunFounder PiSloth - Remote Control

SunFounder PiSloth
113 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
SunFounder pisloth
4.8 Remote Control
In this project, we will learn how to use the keyboard to remotely control the PiSloth. You can control the PiSloth to
move up, down, left, and right and speak through specific keys.
Run the Code
cd /home/pi/pisloth/examples
sudo python3 keyboard_control.py
Once the code runs, you can control PiSloth by pressing wasd, play different sound effects by pressing 1234, and
make PiSloth talk by pressing qe.
Press esc to exit.
w: Go Forward
a: Turn Left
s: Backward
d: Turn Right
1: Sound effect: talk1
2: Sound effect: talk2
3: Sound effect: talk3
4: Sound effect: depress2
q: Say: “Oh hello there”
e: Say: “bye”
esc: Quit
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 TTS
import sys
import tty
import termios
import time
sloth = Sloth([1,2,3,4])
tts = TTS()
music = Music()
sloth.set_offset([0,0,0,0])
def readchar():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
(continues on next page)
92 Chapter 4. Play with Python

Related product manuals