本文整理汇总了Python中Arduino.Arduino.Arduino.cmd_dcmotor_setup方法的典型用法代码示例。如果您正苦于以下问题:Python Arduino.cmd_dcmotor_setup方法的具体用法?Python Arduino.cmd_dcmotor_setup怎么用?Python Arduino.cmd_dcmotor_setup使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arduino.Arduino.Arduino
的用法示例。
在下文中一共展示了Arduino.cmd_dcmotor_setup方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_dcmotor_setup [as 别名]
class DCMOTOR_ROTATION:
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.pin2=10
self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pin1,self.pin2)
self.obj_arduino.cmd_dcmotor_run(1,1,100)
sleep(2)
self.obj_arduino.cmd_dcmotor_release(1,1)
def exit(self):
self.obj_arduino.close_serial()
示例2: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_dcmotor_setup [as 别名]
class SENSE:
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):
jlast=0
k=0
j=0
self.pin1=9
self.pin2=10
self.intrp=5
ilast=self.obj_arduino.cmd_digital_in(1,self.intrp)
self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pin1,self.pin2) # Initialize motor of the interrupt
for s in range(5000):
self.obj_arduino.cmd_dcmotor_run(1,1,100) # Rotate the motor
i=self.obj_arduino.cmd_digital_in(1,self.intrp) # Read the signal of the receiver of IR sensor
if i!=ilast: # Check whether the motor is rotating
if i=='1': # Condition when the receiver receives the signal from transmitter
j=j+1
sleep(0.01)
ilast=i
if j!=jlast:
print j
if j%17==0 and j!=0: # Condition for one complete rotation
k=k+1 # No of rotations
print 'number of rotations completed are',k
jlast=j
self.obj_arduino.cmd_dcmotor_release(1,1)
def exit(self):
self.obj_arduino.close_serial()
示例3: __init__
# 需要导入模块: from Arduino.Arduino import Arduino [as 别名]
# 或者: from Arduino.Arduino.Arduino import cmd_dcmotor_setup [as 别名]
class ENCODER:
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):
count=0;
self.pwm1=9
self.pwm2=10
self.pin1=3
self.pin2=4
pinAlast=self.obj_arduino.cmd_digital_in(1,self.pin1)
self.obj_arduino.cmd_dcmotor_setup(1,3,1,self.pwm1,self.pwm2) # Initialize DC motor
for i in range(2000):
aVal=self.obj_arduino.cmd_digital_in(1,self.pin1)
if aVal!=pinAlast: # To check whether encoder has rotated or not
bVal=self.obj_arduino.cmd_digital_in(1,self.pin2)
if bVal!=aVal: # encoder has rotated in CW direction
count=count+1
print 'clockwise ',count
if count>0 and count<15: # Speed control of DC motor
self.obj_arduino.cmd_dcmotor_run(1,1,40)
sleep(2)
self.obj_arduino.cmd_dcmotor_run(1,1,0)
sleep(1)
if count>=15 and count<30:
self.obj_arduino.cmd_dcmotor_run(1,1,80)
sleep(2)
self.obj_arduino.cmd_dcmotor_run(1,1,0)
sleep(1)
if count<0:
self.obj_arduino.cmd_dcmotor_run(1,1,120)
sleep(2)
self.obj_arduino.cmd_dcmotor_run(1,1,0)
sleep(1)
else: # encoder has rotated in CCW direction
count=count-1
print 'anticlockwise ',count
if count>-15 and count<0: # Speed control of DC motor
self.obj_arduino.cmd_dcmotor_run(1,1,-40)
sleep(2)
self.obj_arduino.cmd_dcmotor_run(1,1,0)
sleep(1)
if count>-30 and count<=-15:
self.obj_arduino.cmd_dcmotor_run(1,1,-80)
sleep(2)
self.obj_arduino.cmd_dcmotor_run(1,1,0)
sleep(1)
if count>0:
self.obj_arduino.cmd_dcmotor_run(1,1,-120)
sleep(2)
self.obj_arduino.cmd_dcmotor_run(1,1,0)
sleep(1)
pinAlast=aVal
self.obj_arduino.cmd_dcmotor_release(1,1)
def exit(self):
self.obj_arduino.close_serial()