当前位置: 首页>>代码示例>>Python>>正文


Python Arduino.cmd_servo_move方法代码示例

本文整理汇总了Python中Arduino.Arduino.Arduino.cmd_servo_move方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.cmd_servo_move方法的具体用法?Python Arduino.cmd_servo_move怎么用?Python Arduino.cmd_servo_move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Arduino.Arduino.Arduino的用法示例。


在下文中一共展示了Arduino.cmd_servo_move方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_servo_move [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:32,代码来源:9.4SERVO.py

示例2: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_servo_move [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()
开发者ID:FOSSEE-Internship,项目名称:PyArduino,代码行数:27,代码来源:9.1SERVO.py

示例3: __init__

# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_servo_move [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 
开发者ID:sbavlani,项目名称:solar-tracker,代码行数:42,代码来源:solar_tracker.py


注:本文中的Arduino.Arduino.Arduino.cmd_servo_move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。