Passing a command line argument into a Python Script causes error -
i have python example script adafruit controls servo , works!
i execute change servomin , servomax values calling 2 values command line. problem having seems not when import sys
, set servomin = (sys.argv)
. im not sure why not accepting int or str. ideas?
here code body:
#!/usr/bin/python adafruit_pwm_servo_driver import pwm import time import sys # =========================================================================== # example code # =========================================================================== # initialise pwm device using default address # bmp = pwm(0x40, debug=true) pwm = pwm(0x50, debug=true) servomin = 150 # min pulse length out of 4096 servomax = 600 # max pulse length out of 4096 def setservopulse(channel, pulse): pulselength = 1000000 # 1,000,000 per second pulselength /= 60 # 60 hz print "%d per period" % pulselength pulselength /= 4096 # 12 bits of resolution print "%d per bit" % pulselength pulse *= 1000 pulse /= pulselength pwm.setpwm(channel, 0, pulse) pwm.setpwmfreq(60) # set frequency 60 hz while (true): # change speed of continuous servo on channel o pwm.setpwm(0, 0, servomin) time.sleep(1) pwm.setpwm(0, 0, servomax) time.sleep(1)
sys.argv
list of arguments, need access arguments, convert them ints.
this should it:
servomin = int(sys.argv[1]) servomax = int(sys.argv[2])
Comments
Post a Comment