SunFounder pisloth
(continued from previous page)
# from robot_hat import TTS
from robot_hat import PWM
from robot_hat import Servo
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])
right_leg_servo = Servo(PWM('P0'))
right_foot_servo = Servo(PWM('P1'))
left_leg_servo = Servo(PWM('P2'))
left_foot_servo = Servo(PWM('P3'))
def readchar():
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
manual = '''
Press keys on keyboard to control PiSloth!
q: Increase the servo angle of the left leg
w: Decrease the servo angle of the left leg
z: Increase the servo angle of the left foot
x: Decrease the servo angle of the left foot
i: Increase the servo angle of the right leg
o: Decrease the servo angle of the right leg
n: Increase the servo angle of the right foot
m: Decrease the servo angle of the right foot
SPACE: Print all angle
ESC: Quit
'''
def main():
print(manual)
left_leg=0
left_foot=0
right_leg=0
right_foot=0
while True:
key = readchar().lower()
# print(key)
if key == "q":
left_leg = left_leg+5
elif key == "w":
(continues on next page)
4.9. Custom Step 97