0

Hi I've got 4 simple codes controlling 2 motors (4 codes for going straight and backwards as well as turning left and right). I am successfully controlling my raspberry pi on my laptop through Putty and what I want now is to assign the 4 codes to the keypress of an arrow key on my laptop.

Should anyone feel the need to look into the 4 codes for my motors I can provide them if you need it.

1

I think you are asking how to handle key presses in Python.

If that is the case I suggest you use the curses module.

Example

#!/usr/bin/env python

import curses

# ./q-curses.py

stdscr = curses.initscr()

curses.noecho()
curses.cbreak()

stdscr.addstr(2, 0, "Press ESC to end")

stdscr.addstr(10, 0, "Hello")
stdscr.addstr(12, 0, "World!")

stdscr.nodelay(1)

count=1

while True:

   stdscr.addstr(14, 12, str(count) + ' ')
   count += 1

   stdscr.refresh()
   time.sleep(0.04)

   c = stdscr.getch()

   if c != -1:
      if c == 27:
          break
      stdscr.addstr(16, 12, str(c) + '   ')

curses.nocbreak()
curses.echo()
curses.endwin()
  • Thx helped a lot! – Panga97 Jan 20 '15 at 16:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.