Ok, at the moment I am working on adding motors to a lego tank that I have. I have one servo in the front to steer and another motor in the rear that will make it go forwards and backwards. i have them both hooked up to a pwm controller from adafruit. I have used their python library and I have some code to move the motors. Now I just am wondering how I can make it so that when the program is running if I hit "w" it will go forward, no having to press enter. Sorry if this seems like a simple problem, I am a beginner programmer.
The full answer is here: https://stackoverflow.com/questions/292095/polling-the-keyboard-in-python
The short answer is:
import sys import select def heardEnter(): i,o,e = select.select([sys.stdin],,,0.0001) for s in i: if s == sys.stdin: input = sys.stdin.readline() return True return False
You will need to generalize this for steering.
sys.stdlin.readline is looking to read everything up to the enter key (newline) You probably just want to do
sys.stdin.read(1) to get a single keystroke.