本文整理汇总了Python中Arduino.Arduino.Arduino.cmd_servo_detach方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.cmd_servo_detach方法的具体用法?Python Arduino.cmd_servo_detach怎么用?Python Arduino.cmd_servo_detach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arduino.Arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.cmd_servo_detach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_servo_detach [as 别名]
class SERVO_POT:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport()
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.pin1=9
self.pot=2
self.pos=0
self.obj_arduino.cmd_servo_attach(1,1)
sleep(1)
self.angle=18
for i in range(100):
val=self.obj_arduino.cmd_analog_in(1,self.pot)
print val
val = int(val*180/1023)
print val
self.obj_arduino.cmd_servo_move(1,1,val)
sleep(0.5)
self.obj_arduino.cmd_servo_detach(1,1)
def exit(self):
self.obj_arduino.close_serial()
示例2: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_servo_detach [as 别名]
class SERVO_INIT:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport()
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.pin1=9
self.obj_arduino.cmd_servo_attach(1,1)
self.obj_arduino.cmd_servo_move(1,1,30)
sleep(1)
self.obj_arduino.cmd_servo_detach(1,1)
sleep(1)
def exit(self):
self.obj_arduino.close_serial()
示例3: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_servo_detach [as 别名]
class SOLAR_TRACKER:
def __init__(self,baudrate):
self.baudrate=baudrate
self.setup()
self.run()
self.exit()
def setup(self):
self.obj_arduino=Arduino()
self.port=self.obj_arduino.locateport() #Locates the port
self.obj_arduino.open_serial(1,self.port,self.baudrate)
def run(self):
self.ldr1=0 #LDR1 connected at port 0
self.ldr2=1 #LDR2 connected at port 1
s=0
self.angle=5 # Step angle
self.initial=90
self.obj_arduino.cmd_servo_attach(1,1) # Attach the servo at pin 9
sleep(1)
self.obj_arduino.cmd_servo_move(1,1,self.initial) #Rotate servo by 90 deg
sleep(1)
for i in range(20):
p=self.obj_arduino.cmd_analog_in(1,self.ldr1) #Read analog input from LDR1
q=self.obj_arduino.cmd_analog_in(1,self.ldr2) # Read analog input from LDR2
print p
print q
sleep(1)
if int(p) < int(q):
s=s+1
self.obj_arduino.cmd_servo_move(1,1,90-self.angle*s) # Clockwise rotation
sleep(1)
else:
s=s-1
self.obj_arduino.cmd_servo_move(1,1,90-self.angle*s) # Anti-clockwise rotation
sleep(1)
self.obj_arduino.cmd_servo_detach(1,1) # Detach the motor
def exit(self):
self.obj_arduino.close_serial() # Close the serial port