How to use keyboard control robot motors - Raspberry Pi Forums


hi guys, i'm new member joined forum share , learn new here.
first post, let me start introduce myself.
name joseph, doing degree in electrical , electronic engineering.
sorry don't have strong programming coding background. i'm stuck in middle of project well.
here start challenge part. i'm doing robot arm servo, not able run "while def" when pressing keyboard.
requirement: when pressing key turn on gpio, when release key turn off gpio. additional condition, without pressing [enter] after key pressed.

code: select all

import rpi.gpio io import time io.setmode(io.bcm) io.setup(8, io.out) motor1 = io.pwm(8,50) motor1.start(0) motor1.changedutycycle(0) io.setwarnings(false)  def servo1_left():     motor1.changedutycycle(2.5)     time.sleep(.1)     return  def servo1_right():     motor1.changedutycycle(10)     time.sleep(.1)     return io.output(8, false)  while true:     char = raw_input()     if(char == "a"):         servo1_left()        if(char == "d"):         servo1_right()      if(char == "x"):         break     io.cleanup()  

i use pygame joystick robot / servo control , switched gpio functions pigpio allows use of local or remote rpi.

using joystick or game pad allows finer control of servos , motors being able give several inputs @ same time. pygame examples games , includes code not needed input. if use pygame joystic input should check make sure hooked , axis which.

dale


raspberrypi



Comments