EasyManua.ls Logo

SunFounder PiSloth - Page 97

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
(continued from previous page)
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
manual = '''
Press keys on keyboard to control PiSloth!
w: 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
'''
def main():
print(manual)
while True:
key = readchar().lower()
# print(key)
if key == "w":
sloth.do_action('forward', 1, 90)
elif key == "a":
sloth.do_action('turn left', 1, 90)
elif key == "s":
sloth.do_action('backward', 1, 90)
elif key == "d":
sloth.do_action('turn right', 1, 90)
elif key == "1":
music.sound_effect_play('./sounds/talk1.wav')
elif key == "2":
music.sound_effect_play('./sounds/talk2.wav')
elif key == "3":
music.sound_effect_play('./sounds/talk3.wav')
elif key == "4":
music.sound_effect_play('./sounds/depress.wav')
elif key == "q":
tts.say("Oh hello there")
elif key == "e":
tts.say("bye")
elif key == chr(27): # 27 for ESC
break
time.sleep(0.05)
print("\nQuit")
if __name__ == "__main__":
main()
How it works?
This function refers to the standard input stream and returns the first character of the data stream read.
4.8. Remote Control 93

Related product manuals